目录的rmarkDown表更改字体颜色

发布于 2025-02-03 05:38:15 字数 2233 浏览 3 评论 0原文

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

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

”在此处输入图像说明”

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2025-02-10 05:38:15

如果您使用真实的乳胶分段命令,则可以指定标题,因为它应该在文本中出现以及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......

“在此处输入图像说明”

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文