内容的 Rmarkdown table 更改字体颜色

Rmarkdown table of contents changes font color

我正在尝试为混合乳胶 R 降价文档中的 table 内容使用自定义颜色。我将 table 的内容设置为 webblue 颜色,并希望我的部分和小节是不同的字体颜色,但是,当我将颜色更改为 'niceblue' 时,table 中的条目的内容也更改为 'niceblue'。问题:如何在不更改内容 table 颜色的情况下更改文档部分的颜色?谢谢你的帮助。请参阅下面我使用的代码:

---
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......

如果您使用真正的 Latex 分节命令,您可以指定应出现在文本中的标题以及目录的标题:

---
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......