Change Paper Size and Orientation in an Rmarkdown PDF

Change paper size and orientation in an rmarkdown pdf

It doesn't seem to be documented, but you can include more than one classoption by separating the options with commas or by using a bulleted list with hyphens. Either of the following will work:

---
title: "Test"
output:
pdf_document:
toc: true
number_sections: true
documentclass: article
classoption:
- landscape
- a3paper
---

---
title: "Test"
output:
pdf_document:
toc: true
number_sections: true
documentclass: article
classoption: landscape, a3paper
---

How can I change paper size when using Knit PDF in RStudio?

OK, so I figured it out. In the .Rmd file's header, options documentclass and classoption get written into the preamble of the resulting .tex file. The article document class accepts a number of paper size options including a4paper. The header in the .Rmd file will then look something like this:

---
title: "Title"
author: "Name"
date: "Date"
output:
pdf_document
documentclass: article
classoption: a4paper
---

For more information see: http://rmarkdown.rstudio.com/pdf_document_format.html

How to specify a customized paper size in r markdown

Use the geometry option in the YAML (which becomes options to the geometry package in LaTeX). For example:

---
title: "Title"
author: "Me"
geometry: paperheight=8.5in,paperwidth=5.5in,margin=1in
output:
pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting
syntax for authoring HTML, PDF, and MS Word documents. For more
details on using R Markdown see <http://rmarkdown.rstudio.com>.

Is there a way to specify portrait/landscape orientation per page using pdf()?

I'm not sure if you can alter the pdf orientation in the middle of a run. You could write out to two files and merge them together using the staplr package. See here.

Set margin size when converting from Markdown to PDF with pandoc

Recent versions of rmarkdown and pandoc

In more recent versions of rmarkdown, the settings of margins can be done in the YAML header via the top-level element geometry. What you specify in the geometry tag will be piped into the LaTeX template that ships with Pandoc via the following LaTeX snippet

$if(geometry)$
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$endif$

For example, to specify margins that are 2cm in width one would include

---
title: "Habits"
author: John Doe
date: March 22, 2005
geometry: margin=2cm
output: pdf_document
---

For more complex specifications to be passed to the geometry LaTeX package, string options together as you would with LaTeX:

---
title: "Habits"
author: John Doe
date: March 22, 2005
geometry: "left=3cm,right=3cm,top=2cm,bottom=2cm"
output: pdf_document
---

Original answer

This is a LaTeX question as Pandoc is rendering to PDF via LaTeX - what you linked to represents the default margins on a LaTeX document.

The geometry LaTeX package for example can be used to alter the margins of the page. However you'll need a way to tell Pandoc to use this by including it ins the LaTeX header applied to the converted md file.

How you do this is documented in the Pandoc User Guide. See in particular the --template=FILE command line argument and the Templates section. Essentially, either find and modify the default template to include the LaTeX instructions you want to use or start your own template from scratch and place it in the appropriate location; see the --data-dir command line argument.


Another alternative if you are using a recent version of Pandoc is to use the variable argument (set either with -V KEY[=VAL] or --variable=KEY[:VAL]). The geometry package was added to the default LaTeX template in May 2012 (see this discussion). As such, if you wanted to change the page margins, you can use:

pandoc -V geometry:margin=1in -o output.pdf input.md

You can specify multiple variable values too. For instance, if you wanted to create a 4 by 6 inch pdf with half-inch margins, you can use:

pandoc -V geometry:paperwidth=4in -V geometry:paperheight=6in -V geometry:margin=.5in -o output.pdf input.md


Related Topics



Leave a reply



Submit