How to add title to R markdown TOC

Is it possible to add a title to the TOC generated by the R markdown document.

In particular, I now have something like this:

--- title: "The Rebel Base Locations" author: "Darth Vader" date: "A long time ago in a galaxy far far away" output: html_document: css: custom.css toc: true toc_depth: 3 number_sections: true --- 

I want the TOC to have a title called "Content." I was able to push it left using some css.

+5
source share
1 answer

You can add a new field right before the table of contents in the html template. Follow these instructions to do the following:

  • Copy the html template to your .rmd file and change the $toc$ field to the following:
 $if(toc)$ <div id="$idprefix$TOC"> <h1 class="toctitle">$toctitle$</h1> $toc$ </div> $endif$ 
  1. Then add the toctitle and template fields to your RMarkdown file. For instance:
 toctitle: "Contents" output: html_document: template: toctitle.html css: custom.css toc: true toc_depth: 3 number_sections: true 

This should add a title before your TOC. You can make other changes, for example. change from h1 to another tag and / or use the field class in CSS. If you have problems that you are not using the default template (mathjax will not work), you can change the default style and not add totctitle to another rmd file later should not be a problem.

+3
source

All Articles