通过 RMarkdown 更改 pdf 输出中所有 headers 的颜色

Changing color of all headers in pdf output by RMarkdown

我想更改 Rmarkdown 创建的 pdf 文档中所有 headers 的颜色。 headers 在黑色中不正确可见。我正在通过乳胶中的这段代码更改字体和大小。

---
title: "PBMC proliferation assay"
author: "Koundinya Desiraju"
output:
  pdf_document:
    highlight: tango
    keep_tex: yes
    number_sections: yes
    toc: yes
---


\fontsize{14}{20}
\selectfont

有没有办法用这样的脚本来做到这一点?我对乳胶的知识是零。所以,请帮助我。基本上我希望 RMarkdown 中 # 或 ## 指定的所有标题在 pdf 中采用不同的颜色。

headers 转到 .tex 文件作为 \section 和 \subsection。我认为解决这个问题最简单的方法是结合这两个 posts:

https://tex.stackexchange.com/questions/171711/how-to-include-latex-package-in-r-markdown

解释如何使用同一文件夹中的 .sty 文件向 tex 文档添加序言。

还有这个post:

https://tex.stackexchange.com/questions/59726/change-size-of-section-subsection-subsubsection-paragraph-and-subparagraph-ti

其中解释了如何在 latex 中使用 titlesec 包。

你的 rmd 应该是这样的:

---
title: "PBMC proliferation assay"
author: "Koundinya Desiraju"
output:
  pdf_document:
    includes:
      in_header: mystyles.sty
    highlight: tango
    keep_tex: yes
    number_sections: yes
    toc: yes
---

# HEADER 1
## HEADER 2

并且您应该创建一个名为 mystyles.sty 的文件,类似于:

\usepackage{titlesec}

\titleformat*{\section}{\LARGE\bfseries}
\titleformat*{\subsection}{\Large\bfseries}

谢谢乔恩。为了完成,我发布了答案。您在 mystyles.sty 文件中提到的代码仅更改 headers 的大小和字体。但是如果我必须改变颜色,保持RMarkdown文档不变,mystyles.sty的内容如下。

\usepackage{titlesec}

\titleformat{\section}
{\color{red}\normalfont\Large\bfseries}
{\color{red}\thesection}{1em}{}
\titleformat{\subsection}
{\color{red}\normalfont\Large\bfseries}
{\color{red}\thesubsection}{1em}{}

您发布的链接非常有用谢谢。