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 the css
option if the output is HTML. Some output formats have their unique themes, such as gitbook
, tufte_html_book
, and tufte_book2
, and you may not want to customize these themes too much. By comparison, the output formats html_book()
and pdf_book()
are not tied to particular themes and more customizable.
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, including default
, cerulean
, journal
, flatly
, darkly
, readable
, spacelab
, united
, cosmo
, lumen
, paper
, sandstone
, simplex
, and yeti
. You can set the theme via the theme
option, e.g.,
---
output:
bookdown::html_book:
theme: united
---
If you do not like any of these Bootstrap styles, you can set theme
to null
, and apply your own CSS through the css
or includes
option.
For pdf_book()
, besides the in_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 the scrbook
class from the KOMA-Script package:
---
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 using in_header
, or even design a custom Pandoc LaTeX template to accommodate these document classes.
Note that when you change documentclass
, 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 when documentclass
is book
), e.g.,
documentclass: krantz
output:
bookdown::pdf_book:
pandoc_args: --top-level-division=chapter