【问题标题】:Header and footer in YAML metablock for rmarkdown and pandocrmarkdown 和 pandoc 的 YAML 元块中的页眉和页脚
【发布时间】:2015-10-28 10:02:09
【问题描述】:

是否可以在 YAML 元块中指定 pdf 页眉和/或页脚?您可以将其设置为出现在每个页面上。这是在 rmarkdown 中,然后将呈现为 pdf(使用 pandoc 和 knitr)。我找不到任何东西(页眉:和页脚:很遗憾没用!)

---
title: testpdf | test
footer: "test footer"
theme: "zenburn"
date: "`r Sys.Date()`"
output: "pdf_document"
fig_width: 12
fig_height: 6
fig_caption: true
---

【问题讨论】:

    标签: yaml knitr r-markdown pandoc


    【解决方案1】:

    没有对页眉和页脚的原生 pandoc-markdown 支持。但是,由于 pandoc 通过 Latex 生成 pdf 文档,您可以调整您的 Latex 模板以适应这些。

    从默认模板创建一个新模板:

    pandoc -D latex > footer_template.latex
    

    在 Latex 序言中添加以下行(这是一个非常基本的示例,应该产生居中的页脚,如果您需要更高级的内容,请参阅 fancyhdr user manual

    $if(footer)$
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \fancyfoot[C]{$footer$}
    $endif$
    

    最后,将此添加到您的文档 yaml 标题中:

    output: 
      pdf_document:
        template: test.latex
    

    您的模板应该位于~/.pandoc/templates 或与test.rmd 相同的目录中才能正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-28
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      相关资源
      最近更新 更多