TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Pandoc uses Tex as an intermediary step when generating PDF, so I thought asking this question on the Tex part of StackExchange may be the right place. If not, please let me know, and I will delete it.

How do you specify that Pandoc should use a specific header and footer when generating a PDF from Markdown?

Currently I use the following to create my doc from the command line:

pandoc -s -V geometry:margin=1in --number-sections -o doc.pdf doc.mkd

This gives a lovely result with numbered sections.

What I would like to do, is to include a header and footer on each page. How do I go about it?

The extensions mechanism, e.g. pandoc_title_block may hold the key, but how do you use it?

Lastly (as a bonus), is there some way to create a title page for a document using pandoc?

share|improve this question
One option would be writing a new template file and including it via the --template option. You could also add all the titling code you need there. – DG' Oct 16 '13 at 14:04
up vote 43 down vote accepted

With pandoc 1.12.x and it’s new YAML metadata capabilities you could add all the information and all LaTeX-code you need in your markdown document like this:

title: Test
author: Author Name
    - \usepackage{fancyhdr}
    - \pagestyle{fancy}
    - \fancyhead[CO,CE]{This is fancy}
    - \fancyfoot[CO,CE]{So is this}
    - \fancyfoot[LE,RO]{\thepage}
abstract: This is a pandoc test . . . 

That way you don't have to modify the template, simply calling pandoc doc.md -o doc.pdf will suffice.

If you want more control, you can add new metadata like this:

title: Test
author: Author Name
header: This is fancy
footer: So is this
geometry: margin=1in
abstract: This is a pandoc test . . . 

# This is a test

Lorem ipsum....

To make this work, you have to modify the template (pandoc -D latex > template.latex) accordingly:

% filename: template.latex


% -----------------------
% Using abstracts

% -----------------------
% Using fancy headers and footers

\usepackage{fixltx2e} % provides \textsubscript
% use upquote if available, for straight quotes in verbatim environments
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\else % if luatex or xelatex
% use microtype if available
% Redefine \includegraphics so that, unless explicit options are
% given, the image width will not exceed the width of the page.
% Images get their normal width if they fit onto the page, but
% are scaled down if they would overflow the margins.
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
            pdfborder={0 0 0}}
\urlstyle{same}  % don't use monospace font for urls
% Make links footnotes instead of hotlinks:
% avoid problems with \sout in headers with hyperref:
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\VerbatimFootnotes % allows verbatim text in footnotes

\author{$for(author)$$author$$sep$ \and $endfor$}



% Adding the abstract







This is also the place to create a title page. As you can see, the template is nothing but a LaTeX document with some $variables$, so it should be easy to customize to your liking.

Now just call pandoc with the template option:

pandoc -s -N --template=template.latex doc.md -o doc.pdf

share|improve this answer
Thanks – I didn't know about the YAML metadata. I noticed that by adding toc: yes I can achieve the --toc command line argument. I wasn't able to recreate the --number-sections argument in the same way though, and wondered why, and if there is a way to do this? – Benjohn May 27 '15 at 12:49
@Benjohn this is probably a new question . . . but try numbersections: yes. You can printout the template with pandoc -D latex to figure the variable names. – DG' May 27 '15 at 18:16
Thanks! I did ask a new question, but I put it on Stack Overflow as I wasn't sure if this TeX SE was happy as the assumed place for Pandoc questions. I got the same answer there, and also a link to panzer. – Benjohn May 27 '15 at 18:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.