14

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?

luciano
  • 13,158
  • 36
  • 90
  • 130
  • 1
    The position (alignment) of the title(s) depends on the LaTeX stylesheet/template you are using (see the `--template` parameter of `pandoc`), not on the markdown bits. Or you can manually add some LaTeX syntax (e.g. `\begin{center}...\end{center}`) in your markdown file. – daroczig May 07 '13 at 14:23
  • This latex code worked: \begin{center} \fontsize{16}{36}\selectfont \textbf{This is my title} \end{center}. Didn't realise you could mix and match latex and markdown. Please convert comment to answer and I will accept. – luciano May 07 '13 at 15:13

1 Answers1

27

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)

mnel
  • 113,303
  • 27
  • 265
  • 254