- CATALOG -
Zhenguo Zhang's Blog
Sharing makes life better
[R] Rmarkdown themes

Rmarkdown is a powerful tool to write documents once and can generate different kinds of output formats such as PDF, html, docx, etc.

Along with it, there are many resources for using the rmarkdown. One of them is tons of themes for shaping the output style.

For the html_document output, in addition to the default theme, there are other builtin ones, including: “cerulean”, “cosmo”, “flatly”, “journal”, “lumen”, “paper”, “readable”, “sandstone”, “simplex”, “spacelab”, “united”, and “yeti”.

To change the theme, use the following code in YAML header:

title: 'theme test'
author: "Your name"
date: '2021-02-01'
output:
  html_document:
    theme: united

In addition to the builtin themes, there are many packages providing extra themes, such as rmdformats, prettydoc, hrbrthemes, tufte, and tint.

For using these external themes, one need install the package first, and then use the following YAML code to activate them (use rmdformats::readthedown as an example):

title: 'theme test'
author: "Your name"
date: '2021-02-01'
output:
  rmdformats::readthedown:
    toc_depth: 3

Note that the output format changes to the theme name (here rmdformats::readthedown), one can actually check the corresponding theme function [rmdformats::readthedown()] to see available options for the theme.

With themes, the output style change is much easier, for example, the theme rmdformats::readthedown provides a float table of contents to the left page panel and different background colors for the panels.

One can see effects of more themes here.

Happy coding!


Last modified on 2021-02-03

Comments powered by Disqus