【问题标题】:Creating a footer for every page using R markdown使用 R markdown 为每个页面创建页脚
【发布时间】:2014-08-15 15:32:42
【问题描述】:

我正在用 R Markdown 编写一个文档,我希望它在我编织 PDF 文档时在每一页上都包含一个页脚。有没有人知道如何做到这一点?

【问题讨论】:

  • 对于花哨的东西使用 LaTex 而不是 Markdown!
  • @EDi 说了什么。要将 LaTeX 与 R 一起使用,请尝试 knitr。

标签: r-markdown knitr pandoc


【解决方案1】:

是的,此问题已在此处提出并回答:Adding headers and footers using Pandoc。您只需在 Markdown 文档的 YAML 标头中添加一点 LaTeX。

这个 Markdown 标题可以解决问题:

---
title: "Test"
author: "Author Name"
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy header}
- \fancyfoot[CO,CE]{And this is a fancy footer}
- \fancyfoot[LE,RO]{\thepage}
output: pdf_document
---

使用RStudio Version 0.98.1030 for Windows 中的 Rmd 文件为我工作。

【讨论】:

    【解决方案2】:

    另一种选择是使用rmarkdown::pdf_document() (documentation) 提供的参数includes。这允许您将页脚保存在单独的文件中。如果您的页脚是在footer.tex 中定义的,那么您的 R Markdown 文件的标题将如下所示:

    ---
    output:
      pdf_document:
        includes:
          after_body: footer.tex
    ---
    

    这还假设footer.tex 与 R Markdown 文件位于同一目录中。

    更新:文件footer.tex 可以包含您想要插入到PDF 文档末尾的任何有效LaTeX。例如,footer.tex 可能包含以下内容:

    This \textbf{text} will appear at the end of the document.
    

    【讨论】:

    • 你能提供一个示例footer.tex吗?最少的内容是什么?
    • 您可以将任何有效的 LaTeX 放入 footer.tex。它将被插入到 PDF 文档的末尾。我用一个例子更新了我的答案。
    【解决方案3】:

    要管理页脚的高度,您可以使用以下内容:

    date: '`r paste("Date:",Sys.Date())`'
    output:
      pdf_document: 
        latex_engine: xelatex
    header-includes:
          - \setlength{\footskip}{-50pt} # set the footer size
    

    继续编码!

    【讨论】:

      猜你喜欢
      • 2015-09-04
      • 2018-02-12
      • 1970-01-01
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多