centre title in PDF converted from markdown using Pandoc

luciano picture luciano · May 7, 2013 · Viewed 8.1k times · Source

I'm converting a markdown document to a PDF document using Pandoc from within R. I'm trying to centre the title.

So far, I've tried:

 <center># This is my title</center>

and

-># This is my title<-

but neither have worked. Is there a way to centre the title when converting from markdown to PDF using Pandoc?

Answer

mnel picture mnel · May 8, 2013

pandoc has its own extended version of markdown. This includes a title block.

If the file begins with a title block

% my title
% Me; Someone else
% May 2013

This will be parsed into LaTeX and the resulting pdf as

\title{my title}
\author{Me \and Someone Else}
\date{May 2013}

and then `

\maketitle

called within the document.

This will create the standard centred title.

If you want to change how the title etc is formatted you could use the titling package.

If you want to change how the section headers are formatted, you could use the titlesec package.

To automagically have pandoc implement these you could define your own template. A simpler option is to have a file with your desired latex preamble to be included in the header. and then use the appropriate arguments when calling pandoc (eg -H FILE or --include-in-header=FILE)