Exercise

Add a table of contents

Another cool feature of RMarkdown reports (whether HTML or PDF) is an automatically generated table of contents (TOC). And with several settings, you can customize your TOC quite a bit:

You add a table with toc: true and specify whether it should be floating (i.e. whether it moves along as you scroll) with toc_float: true or toc_float: false.

The depth of your TOC is set with toc_depth (e.g. toc_depth: 3).

Instructions

100 XP

Add additional keys to your YAML header after the highlight key so that:

  • Your report contains a TOC (using the toc key).
  • Your TOC does not float (using the toc_float key).
  • Your TOC also displays the level 4 section header at the end of the report. By default, TOCs go only two levels of sections deep.
    • Use the toc_depth key together with the correct value for this.