I am trying to change the color of the title in an Rmd file that generates a Pdf
I tried this (with and without quotes):
---
title: "\textcolor{blue}{This title is blue}"
output:
pdf_document:
latex_engine: xelatex
---
# 1. TITLE 1
## 1.1 Subtitle
which gives this kind of error:
Error: Failed to compile test_font.tex.`
And then I tried this:
---
title: <div class="blue">This title is blue</div>
output:
pdf_document:
latex_engine: xelatex
---
# 1. TITLE 1
## 1.1 Subtitle
which doesn't change the color
Any advice? Thanks!
I found a way to change the color of titles of PDFs compiled from RMarkdown files by doing the following. This process does not require any manual modification of intermediate TeX files.
I have a header file that contains LaTeX code to import the color package and define some custom colors, it is named header.tex.
\usepackage{color}
\definecolor{NavyBlue}{RGB}{0,112,192}
The YAML section of my RMarkdown file contains the following lines in the ouput section.
output:
pdf_document:
includes:
in_header: header.tex
keep_tex: true
toc: false
And the title line is the following.
title: \textcolor{NavyBlue}{`r paste0('Report - ', params$Location)`}
The resulting title looks like this.

If you are using TinyTeX you should not need to worry about downloading any packages.
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