6.4 Include additional LaTeX packages
The use of additional LaTeX packages can allow for extensive customization of document styling. In addition, several packages such as kableExtra (Zhu 2020) may have LaTeX dependencies for the R package to function. Much like R, we need to load packages within the R Markdown document before we are able to use their functions.
6.4.1 Loading LaTeX packages
We can load additional LaTeX packages using the
extra_dependencies option within the
pdf_document YAML settings. This allows us to provide a list of LaTeX packages to be loaded in the intermediate LaTeX output document, e.g.,
If you need to specify options when loading the package, you can add a second level to the list and provide the options as a list, e.g.,
For those familiar with LaTeX, this is equivalent to the following LaTeX code:
The advantage of using the
extra_dependencies argument over the
includes argument introduced in Section 6.1 is that you do not need to include an external file, so your Rmd document can be self-contained.
6.4.2 Example packages
There is an extensive community for LaTeX, and there are over 4,000 packages available through the Comprehensive TeX Archive Network (CTAN). Here are some examples of LaTeX packages you could consider using within your report:
Zhu, Hao. 2020. KableExtra: Construct Complex Table with Kable and Pipe Syntax. https://CRAN.R-project.org/package=kableExtra.