I have recently learned that modifying the default (Pandoc?) template for a Rmd
pdf report gives access to some neat customisation.
So in order to modify the default template I first move it to my working directory using:
file.copy(system.file("rmd/latex/default-1.17.0.2.tex", package ="rmarkdown"), "template.tex")
Next I type up my Rmd
file:
---
output:
pdf_document:
template: template.tex
keep_tex: true
latex_engine: xelatex
includes:
in_header: in_header.tex
number_sections: true
---
This is a rmd kind of document.
Where in_header.tex
includes only one line
\geometry{a4paper, top=38mm, left=45mm, right=45mm}
I first just want to run the Rmd
file with the template as is (expecting no change) but the report fails to compile if and only if I include the template - otherwise it runs without an issue.
The error is
! Undefined control sequence.
l.58 \geometry
[...]
Question
How can I use the template argument to build on an editable template in my working folder without causing any other change to my current setup.
Info
> R.Version()[["version.string"]]
[1] "R version 3.5.1 (2018-07-02)"
> packageVersion("rmarkdown")
[1] ‘1.10’
> packageVersion("knitr")
[1] ‘1.20’
An .Rmd template is essentially the replacement for a worksheet. It is a partially-filled out R Markdown file that you can create. You can create a template for every homework assignment or exercise that you want your students to work through. And they can access all of these templates easily when they go to File > New File > R Markdown.
As we just mentioned, the document template.docx has to be generated from Pandoc. You can create this template from an arbitrary R Markdown document with the word_document output format (the actual content of this document does not matter, but it should contain the type of elements of which you want to style).
Many aspects of the LaTeX template used to create PDF documents can be customized using top-level YAML metadata (note that these options do not appear underneath the output section, but rather appear at the top level along with title, author, and so on). For example:
3.3. PDF document. To create a PDF document from R Markdown, you specify the pdf_document output format in the YAML metadata: --- title: "Habits" author: John Doe date: March 22, 2005 output: pdf_document ---. Within R Markdown documents that generate PDF output, you can use raw LaTeX, and even define LaTeX macros.
As you are already driving this from R, you may as well use the (excellent) example set up by the rticles package which provides a larged number of LaTeX customizations for (academic) papers.
And you can then run with that them. For example, over the last two years I added these packages:
This allows you to
template.tex
I find this preferable to copying stanzas around which I did previously (eg for slides).
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