Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a title and numbering of sections on pdf while using R markdown with pandoc

I am using the markdown document created by R and I am trying to create the pdf file from the markdown using pandoc. Everything else works fine but I want the title of the document to appear and the numbering on the sections as in default Latex document. It seems the title defined on rmarkdown appears as a section title for the pdf.

I was able to create double spacing, enter line numbers etc by using a options.sty file. Below is the code that I used to create a pdf.

For options.sty I used:

 \usepackage{setspace}
\doublespacing

\usepackage[vmargin=0.75in,hmargin=1in]{geometry}
\usepackage{lineno}
\usepackage{titlesec}

\titleformat{\section}
{\color{red}\normalfont\Large\bfseries}
{\color{red}\thesection}{1em}{}

\titleformat{\subsection}
{\color{blue}\normalfont\Large\bfseries}
{\color{blue}\thesection}{0.8em}{}


\title{Monitoring Stations}
\author{Jdbaba}

I used knitr to create the R markdown file. In the above options.sty file, it seems the program is not taking title and author part. It seems I am missing something.

The code I used to convert markdown to pdf is as follows:

pandoc -H options.sty mydata.md -o mydata.pdf

In latex document, the pdf would have the automatic numbering as well. But my pdf is missing that. Can anyone suggest how numbering can be enabled on the pdf document created using pandoc ?

Thanks.

like image 654
Jd Baba Avatar asked Mar 06 '13 18:03

Jd Baba


People also ask

Can pandoc convert from PDF?

You can use the program pandoc on the SCF Linux and Mac machines (via the terminal window) to convert from formats such as HTML, LaTeX and Markdown to formats such as HTML, LaTeX, Word, OpenOffice, and PDF, among others.

How do I create a PDF in R markdown?

To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.

Can pandoc convert HTML to PDF?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx. For the full lists of input and output formats, see the --from and --to options below. Pandoc can also produce PDF output: see creating a PDF, below.


1 Answers

Pandoc takes the title from a title block in the Markdown file. This is a Pandoc-specific extension to Markdown. The block should have the following format:

% title
% author(s) (separated by semicolons)
% date

So, in your case:

% Monitoring Stations
% Jdbaba
% March 6, 2013

To have the sections numbered, you'll need to run Pandoc with the --number-sections option.

like image 54
Jason Blevins Avatar answered Sep 26 '22 02:09

Jason Blevins