Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

By default the PDF documents created by the Knit PDF are US Letter size. Instead I would like to create A4 size documents. I have a feeling this should simple to change, either in the RStudio GUI or by adding an option to the metadata at the top of the Rmd file. Unfortunately I can't find any instructions how to do this. Is there a way to specify paper size, preferably within the Rmd file itself? I am still using RStudio version 0.98.953 but can upgrade if it would help.

I'd be grateful if someone could point me in the right direction.

like image 751
Nicholas Avatar asked Sep 16 '14 10:09

Nicholas


People also ask

How do you Knit a PDF in RStudio?

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.

What does Knit document mean on RStudio?

Better still, RStudio includes a “Knit” button that enables you to render an . Rmd and preview it using a single click or keyboard shortcut.

How do I print an R notebook to PDF?

The format, by default, will be set to HTML, but you can change it to PDF or Word document by clicking on the small arrow beside the Preview button and selecting “Knit to PDF” or “Knit to Word document”. The most powerful feature of R notebook is that it is interactive.


2 Answers

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

like image 114
Nicholas Avatar answered Oct 17 '22 19:10

Nicholas


At least in newer versions of the rmarkdown R package (and Pandoc) you can just set:

---
output: pdf_document
papersize: a4
---
like image 43
Salim B Avatar answered Oct 17 '22 19:10

Salim B