I have some custom color and I'd like the headers of fancyhdr to be colored differently.

How do you make the different headers \fancyhead[L], \fancyhead[R], \fancyhead[C] have different colorboxes and font colors? How do you make \fancyhead[R] have a different font size?

Thank you.

Here is what I currently have:

---
title: "Untitled"
classoption: landscape
output:
pdf_document:
number_sections: false
dev: pdf
keep_tex: false
toc: yes
- \usepackage{fancyhdr}
- \usepackage{etoolbox}
- \usepackage{color}
- \pagestyle{fancy}
- \definecolor{col1}{RGB}{7, 252, 3}
- \definecolor{col2}{RGB}{7, 200, 3}
\colorbox{col1}\color{blue}{left}%
}
\colorbox{col2}\color{red}\fontsize{12?}{right}%
}
- \fancyhead[C]{  %  \colorbox{col2}\color{white}\nouppercase{\leftmark} %   }
---

{r setup, include=FALSE}
knitr::opts_chunk\$set(echo = TRUE)


## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

{r cars}
summary(cars)


\newpage

# Including Plots

You can also embed plots, for example:

{r pressure, echo=FALSE}
plot(pressure)


Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

\newpage

# page 3

You can also embed plots, for example:

{r pressured, echo=FALSE}
plot(pressure)


Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.


• \colorbox{<colour>}{<stuff>} takes two arguments. The first is the <colour>, while the second is the <stuff> contained within the box. Using

- \fancyhead[L]{%
\colorbox{col1}\color{blue}{left}%
}


mistakenly puts \color as the second argument to \colorbox, which doesn't make sense. You need to use something like

- \fancyhead[L]{\colorbox{col1}{\color{blue}left}}


Note also the use of a single line rather than breaking a line; writing header content (via header-includes) in Markdown doesn't translate in the same way you'd think.

• To change the font size, use \fontsize{<size>}{<baseline skip>}\selectfont. In your case, something like \fontsize{12}{14}\selectfont would work.

- \setlength{\headheigh}{<height>}

to match your needs (where <height> is at least as large as the suggested height).