更改r bookdown中的章节颜色(pdf输出)

问题描述 投票:2回答:2

在常规的bookdown格式中,每章都以粗体开头:

第1章

章节标题

我试图将“第1章”的颜色改为深灰色,而不是黑色。我是LaTeX的新手,但是根据其他Stackoverflow问题将一些代码拼凑在一起,以自定义颜色。我创建了一个mystyles.sty文件,其中包括:

\usepackage{titlesec}
\usepackage{xcolor}

\definecolor{battleshipgrey}{rgb}{0.52, 0.52, 0.51}
\titleformat{\thechapter}
{\color{battleshipgrey}\normalfont\Large\bfseries}
{\color{battleshipgrey}\chapter}{1em}{}

我的YAML标题是:

title: "My Title"
author: "Me"
date: ""
output: pdf_document
bibliography: [bib.bib]
documentclass: book
geometry: left=4cm, right=3cm, top=2.5cm, bottom=2.5cm
link-citations: yes
classoption: openany
biblio-style: apalike
subparagraph: true

我有一个带有以下代码的_output.yml:

bookdown::pdf_book:
  includes:
    in_header: mystyles.sty
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: no
mainfont: Bookman

我在mystyles.sty文件中指定的内容是什么?目前,没有任何颜色变化。我试过指定:

\titleformat{\chapter}
{\color{battleshipgrey}\normalfont\Large\bfseries}
{\color{battleshipgrey}\thechapter}{1em}{}

但是这会将章节编号和标题灰色设置为颜色,但章节标题的格式将更改为:

1章的标题

r latex r-markdown bookdown
2个回答
1
投票

您可以尝试以下使用xcolor中的sectstymystyes.sty包:

\usepackage{xcolor}
\usepackage{sectsty}
\definecolor{battleshipgrey}{rgb}{0.52, 0.52, 0.51}
\chapterfont{\color{battleshipgrey}}  % sets colour of chapters                                                                                

无论如何,这似乎在我的最终工作,并将产生灰色章节标题没有数字。


0
投票

ekstroem让我走上了正确的道路,使用了sectsty包。我尝试使用sectsty包中的\chapternumberfont,但是没有用。我认为Bookdown没有将章节号的名称设置为此特定名称。通过将整个章节设置为灰色,然后将章节标题设置为黑色,我找到了一个有效的解决方法:

\usepackage{xcolor}
\usepackage{sectsty}
\definecolor{battleshipgrey}{rgb}{0.52, 0.52, 0.51}
\chapterfont{\color{battleshipgrey}}
\chaptertitlefont{\color{black}} 
© www.soinside.com 2019 - 2024. All rights reserved.