I am currently using RStudio 0.98.1091 and I am trying to create a pdf document with the render function from the rmarkdown package.
R script:
library("rmarkdown")
render("input.Rmd", "pdf_document")
input.Rmd
---
title: "Report"
output: pdf_document
---
<style>
body {background-color:lightgray}
</style>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
I would like to set the background color of the whole report, out of desperation I tried a few things like using html; with no results.
The document has graphs plotted with R code chunks, tables, and text.
Again, I would like to set the document background color to something else (currently white).
Thanks,
ZeroStack
I am using OS X 10.10.3 with pandoc and MacTex installed.
Well, one solution is to use latex i.e. first create a .Rnw file which loads the latex pagecolor package:
\documentclass{article}
\usepackage{pagecolor}
\begin{document}
\pagecolor{yellow}
\section{A very yellow page}
<<plot1, echo=FALSE>>=
hist(rnorm(1000))
@
\clearpage
\subsection{Another yellow page}
<<summary1>>=
summary(mtcars)
@
\end{document}
In RStudio this will look like:

You now want to convert this .Rnw file to a .tex file and then to a .pdf file. The easiest way this can be done is simply by pressing the Compile pdf button in RStudio (shortcut Shift+Cmd+K).
If you want to do this programatically you first need to convert the .Rnw to a .tex file with knitr::knit("foo.Rnw"), and then doing in the command line: pdflatex foo.tex, which will produce the .pdf file.
Result:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With