# How does one set document class options (e.g. paper size) for LaTeX output?

The header option lets you insert TeX code in the preamble after \documentclass{article}, but what if I want to change the default paper size or the default font size?

For this, I would need to insert text between \documentclass and {article}, for instance: \documentclass[a4paper,10pt]{article}.

Update: I forgot to mention that I am using spin() to generate the PDF document via LaTeX.

• This is obviously a question about r, why migrated into tex? – kohske Jul 3 '14 at 9:03
• @kohske Seconded - the question and its answers are immaterial to anyone interested in LaTeX outside of how it relates to R Markdown/YAML. – DHW Dec 24 '17 at 4:01

Try this:

#' \documentclass[a4paper, 10pt]{article}
#' \begin{document}

mean(1:10)
plot(1:10)

#' \end{document}


There is support for specifying certain options in the YAML header; a relevant page on the R Markdown website lists the following options:

• lang: Document language
• fontsize: Font size
• documentclass: Document class
• classoption: Options for \documentclass
• geometry: Options for \geometry
• mainfont, sansfont, monofont, mathfont: For Xe(La)TeX and Lua(La)TeX
• linkcolor, urlcolor, citecolor: Options for \hyperref

You may find it useful to check out the default LaTeX template used here.