Rachel
Rachel

Reputation: 325

Header and footer in YAML metablock for rmarkdown and pandoc

Is it possible to specify in the YAML metablock a pdf header and/or footer?Something you could set to appear on every page. This is in rmarkdown and will then be rendered to a pdf (using pandoc and knitr). I have not been able to find anything (header: and footer: sadly did not work!)

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

Upvotes: 5

Views: 4077

Answers (1)

scoa
scoa

Reputation: 19867

There is no native pandoc-markdown support of headers and footers. However, since pandoc generates pdf documents through latex, you can tweak your latex template to accommodate those.

Create a new template from the default one :

pandoc -D latex > footer_template.latex

Add the following lines in the latex preamble (this is a very basic example that should produce a centered footer, see the fancyhdr user manual if you need something more advanced)

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

Finally, add this to your document yaml header :

output: 
  pdf_document:
    template: test.latex

Your template should either be in ~/.pandoc/templates or in the same directory as test.rmd for this to work.

Upvotes: 4

Related Questions