【问题标题】:Changing Chapter colors in r bookdown (pdf output)更改 r bookdown 中的章节颜色(pdf 输出)
【发布时间】:2019-02-07 14:43:28
【问题描述】:

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

第 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


    【解决方案1】:

    您可以尝试以下使用mystyes.sty 中的xcolorsectsty 包:

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

    无论如何,这似乎对我有用,并且会产生灰色的章节标题,没有数字。

    【讨论】:

    • 很抱歉我的回复晚了,我已经有一段时间没能参与这个项目了。对我来说,这将“第 1 章”和“第 1 章标题”都设置为灰色,我只希望它适用于“第 1 章”部分。我将查看 sectsty 包,看看是否可以进一步弄清楚。
    • 我尝试使用 sectsty 包中的\chapternumberfont,但没有成功。我认为 Bookdown 没有将章节编号的名称设置为这个特定的名称。我找到了一个可行的解决方法,将整个章节设置为灰色,然后将章节标题设置为黑色:\chapterfont{\color{battleshipgrey}} \chaptertitlefont{\color{black}}
    【解决方案2】:

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

    \usepackage{xcolor}
    \usepackage{sectsty}
    \definecolor{battleshipgrey}{rgb}{0.52, 0.52, 0.51}
    \chapterfont{\color{battleshipgrey}}
    \chaptertitlefont{\color{black}} 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-16
      • 2021-04-14
      • 2017-03-06
      • 2015-06-03
      • 2019-11-23
      • 1970-01-01
      • 2016-04-03
      相关资源
      最近更新 更多