Rmarkdown table of contents changes font color

Salvador

I am trying to use custom colors for my table of contents on a mixed latex R markdown document. I set the table of contents to be webblue color and want my sections and subsections to be a different font color, however, when I change the color to 'niceblue', the entry in the table of contents also change to 'niceblue'. Question: How can I change the colors of my documents sections without altering the color on table of contents? Thanks for any help. See code that I am using below:

---
title: "Age Assignment"
author: "joe"
date: "`r Sys.Date()`"
output:
  pdf_document: default
header-includes:
- \geometry{top=1.3cm, bottom=1.0cm, left=1.8cm, right=1.8cm,footskip=.5cm}
- \usepackage{hyperref}
- \hypersetup{colorlinks = true, linkcolor = webblue, urlcolor = red}
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
- \usepackage{longtable,ctable}
- \usepackage{url}
- \usepackage{relsize}
- \usepackage[compact]{titlesec}%use 'compact' to shrink the whitespace on sections,sub,subsub
- \hypersetup{pdfstartview={XYZ null null 0.75}}%0.75 prints pdf at 75% zoom level
- \usepackage{setspace}
- \newcommand{\subsubsubsection}[1]{\paragraph{#1}\mbox{}\par\vspace{1mm}} %to add a subsubsubsection
- \setcounter{secnumdepth}{4}               %to add a subsubsubsection
- \setcounter{tocdepth}{4}                  %to add a subsubsubsection
- \titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}%Sections
- \titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}%subsections
- \titlespacing\subsubsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}%subsub
- \definecolor{webblue}{rgb}{0, 0, 0.5} % less intense blue
- \definecolor{bole}{rgb}{0.47, 0.27, 0.23}
- \definecolor{brickred}{rgb}{0.8, 0.25, 0.33}
- \definecolor{niceblue}{rgb}{0.0, 0.53, 0.74}
subtitle: Assessment of populations
number_sections: yes
toc: yes
---

```{r setup, include=FALSE} 
knitr::opts_chunk$set(warning = FALSE, message = FALSE,comment="") 
```
\color{bole}The purpose of this document is to......\
\color{black}

# Beginning of document

## This is a test

## And this is another test...

## \color{niceblue}Introduction
\color{black}
The Central Valley blah blah\par

### \color{niceblue} Methods
\color{black}
And this is what happened......

enter image description here

samcarter_is_at_topanswers.xyz

If you use real latex sectioning commands, you can specify both the title as it should appear in text as well as the title for the toc:

---
title: "Age Assignment"
author: "joe"
date: "`r Sys.Date()`"
output:
  pdf_document: 
    keep_tex: true
header-includes:
- \geometry{top=1.3cm, bottom=1.0cm, left=1.8cm, right=1.8cm,footskip=.5cm}
- \usepackage{hyperref}
- \hypersetup{colorlinks = true, linkcolor = webblue, urlcolor = red}
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
- \usepackage{longtable,ctable}
- \usepackage{url}
- \usepackage{relsize}
- \usepackage[compact]{titlesec}%use 'compact' to shrink the whitespace on sections,sub,subsub
- \hypersetup{pdfstartview={XYZ null null 0.75}}%0.75 prints pdf at 75% zoom level
- \usepackage{setspace}
- \newcommand{\subsubsubsection}[1]{\paragraph{#1}\mbox{}\par\vspace{1mm}} %to add a subsubsubsection
- \setcounter{secnumdepth}{4}               %to add a subsubsubsection
- \setcounter{tocdepth}{4}                  %to add a subsubsubsection
- \titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}%Sections
- \titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}%subsections
- \titlespacing\subsubsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}%subsub
- \definecolor{webblue}{rgb}{0, 0, 0.5} % less intense blue
- \definecolor{bole}{rgb}{0.47, 0.27, 0.23}
- \definecolor{brickred}{rgb}{0.8, 0.25, 0.33}
- \definecolor{niceblue}{rgb}{0.0, 0.53, 0.74}
subtitle: Assessment of populations
number_sections: yes
toc: yes
---

```{r setup, include=FALSE} 
knitr::opts_chunk$set(warning = FALSE, message = FALSE,comment="") 
```
\color{bole}The purpose of this document is to......\
\color{black}

# Beginning of document

## This is a test

## And this is another test...

\subsection[Introduction]{\color{niceblue}Introduction}
\color{black}
The Central Valley blah blah\par

\subsubsection[Methods]{\color{niceblue} Methods}
\color{black}
And this is what happened......

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Choose font size for table of contents only in a rmarkdown-rendered pdf

YAML title font and color in Rmarkdown

How to add table of contents in Rmarkdown?

RMarkdown: Customize Color and Font Size of (automated) Citations

Using Rmarkdown (pagedown) and changing Table of Contents

Rmarkdown add custom div to table of contents

changing rmarkdown "table of contents" default title

How to change the position of the table of contents in rmarkdown?

Adjusting spacing in table of contents for a RMarkdown document

RMarkdown - different font types in table using kable?

Style sheet changes font size but not color?

Change font color in table th

Change table font color Javascript

Change table-striped color in formattable in Rmarkdown

Change table contents upon dropdown list changes

website in Rmarkdown: navbar changes color between index and other pages

Rmarkdown beamer table of contents slides, plus grayed out for not current sections

RMarkdown with knitr to HTML: How to hide bullets in TOC (table of contents)?

RMarkdown: How to change headline in table of contents in R Markdown?

Adding a table of contents on the left side with HTML document in Rmarkdown

How to change font size of table in Rmarkdown, LaTeX and .pdf?

JAVAFX Table View Wrapped Text Font Color

customizing latex table row and font color

Change font color of specific cell in a table

Change angular material table font color

Javascript to change table tab font color

How can I create a TextField that changes font and color on user input?

Table row that highlights on hover and changes color on click

How to customise font size of Table of Contents generated by package{tocloft} in LATEX