Header and footer in YAML metablock for rmarkdown and pandoc

Is it possible to specify a header and / or footer in the YAML metablock? Something that you could install on every page. This is in rmarkdown and then translated to pdf (using pandoc and knitr). I couldn't find anything (header: and footer: unfortunately didn't 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
---

      

+3


source to share


1 answer


There is no built-in support for pandoc-markdown headers and footers. However, since pandoc creates PDF documents via latex, you can customize your latex template to accommodate them.

Create a new default template:

pandoc -D latex > footer_template.latex

      

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



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

      

Finally, add this to the yaml header of your document:

output: 
  pdf_document:
    template: test.latex

      

Your template must either be in ~/.pandoc/templates

or in the same directory as test.rmd

for this to work.

+3


source







All Articles