Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change the title color Rmd file

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!

like image 748
Julien Massardier Avatar asked Jan 20 '26 03:01

Julien Massardier


1 Answers

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.

like image 176
Max Feinberg Avatar answered Jan 22 '26 21:01

Max Feinberg