作者:Yihui Xie
译者:郑宝童
日期:2021.05.31
4.2 Theming
Sometimes you may want to change the overall theme of the output, and usually this can be done through the
in_header
option described in the previous section, or thecss
option if the output is HTML. Some output formats have their unique themes, such asgitbook
,tufte_html_book
, andtufte_book2
, and you may not want to customize these themes too much. By comparison, the output formatshtml_book()
andpdf_book()
are not tied to particular themes and more customizable.
有时您可能想要更改输出的整体主题,这通常可以通过上一节中描述的in_header
选项来完成。如果输出格式是HTML,则可以使用css选项。有些输出格式有其独特的主题,如gitbook
、tufte_html_book
和tufte_book2
,您可能不希望过多地自定义这些主题。相比之下,输出格式html_book()
和pdf_book()
没有绑定到特定的主题,而且更易于定制。
As mentioned in Section 3.1.2, the default style for
html_book()
is the Bootstrap style. The Bootstrap style actually has several built-in themes that you can use, includingdefault
,cerulean
,journal
,flatly
,darkly
,readable
,spacelab
,united
,cosmo
,lumen
,paper
,sandstone
,simplex
, andyeti
. You can set the theme via thetheme
option, e.g.,
如3.1.2节所述,html_book()
的默认样式是Bootstrap样式。Bootstrap风格实际上有几个内置的主题可以使用,包括default
, cerulean
, journal
, flat
, dark
, readable
, spacelab
, united
, cosmo
, lumen
, paper
,sandstone
,simplex
和yeti
。你可以通过主题选项设置主题,例如:
---
output:
bookdown::html_book:
theme: united
---
If you do not like any of these Bootstrap styles, you can set
theme
tonull
, and apply your own CSS through thecss
orincludes
option.For
pdf_book()
, besides thein_header
option mentioned in the previous section, another possibility is to change the document class. There are many possible LaTeX classes for books, such as memoir (https://www.ctan.org/pkg/memoir), amsbook (https://www.ctan.org/pkg/amsbook), KOMA-Script (https://www.ctan.org/pkg/koma-script) and so on. Here is a brief sample of the YAML metadata specifying thescrbook
class from the KOMA-Script package:
如果你不喜欢这些Bootstrap样式,你可以将theme
设置为null
,并通过css
或includes
选项应用你自己的CSS。
对于pdf_book()
,除了前面提到的in_header
选项外,另一种可选的方式是更改文档类。有许多适合书籍的LaTeX类,如memoir (https://www.ctan.org/pkg/memoir), amsbook (https://www.ctan.org/pkg/amsbook), KOMA-Script (https://www.ctan.org/pkg/koma-script) 等。下面是一个简短的YAML元数据示例,它指定了来自KOMA-Script包的scrbook
类:
---
documentclass: scrbook
output:
bookdown::pdf_book:
template: null
---
Some publishers (e.g., Springer and Chapman & Hall/CRC) have their own LaTeX style or class files. You may try to change the
documentclass
option to use their document classes, although typically it is not as simple as that. You may end up usingin_header
, or even design a custom Pandoc LaTeX template to accommodate these document classes. Note that when you changedocumentclass
, you are likely to specify an additional Pandoc argument--top-level-division=chapter
so that Pandoc knows the first-level headers should be treated as chapters instead of sections (this is the default whendocumentclass
isbook
), e.g.,
一些发行商 (e.g., Springer and Chapman & Hall/CRC)有自己的LaTeX风格或类文件。您可以尝试更改documentclass
选项以使用它们的文档类,尽管通常情况下没有那么简单。您可能最终会使用in_header
,甚至设计一个自定义Pandoc LaTeX模板来容纳这些文档类。
注意,当你改变documentclass
时,你可能会指定一个额外的Pandoc参数--top-level-division=chapter
,这样Pandoc就知道第一级的头文件应该被当作章而不是节(chapters instead of sections )(当documentclass
为book
时,这是默认值)
documentclass: krantz
output:
bookdown::pdf_book:
pandoc_args: --top-level-division=chapter