Customizing R Markdown reports
In this section, we will look at adding metadata such as a table of contents to the report, followed by introducing more options for changing the report style.
Adding a table of contents
When reading a report for the first time, a table of contents provides an overview of the report and thus helps readers quickly navigate the different sections of the report.
To add a table of contents, we can append a colon to the html_document
field in the YAML header and set toc: true
as a separate line with one more indentation than the html_document
field. This is shown in the following code snippet:
--- title: "Financial analysis" output: Â Â Â Â html_document: Â Â Â Â Â Â Â Â toc: true date: "2022-10-12" author: "Liu Peng" ---
Knitting the document with these commands produces Figure 6.29, where a table of contents is now displayed at the top of the report. Note that when...