Is it possible to add a title to the TOC generated by an R markdown document.
Specifically, I have something like this now:
---
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
---
What I want is the TOC to have a header called "Contents". I was able to push it to the left using some css.
You can add a new field right before the table of contents in the html template. Following this instructions, do this:
$toc$
field to something like this:$if(toc)$
<div id="$idprefix$TOC">
<h1 class="toctitle">$toctitle$</h1>
$toc$
</div>
$endif$
toctitle
and template
fields to your RMarkdown file. For example:toctitle: "Contents"
output:
html_document:
template: toctitle.html
css: custom.css
toc: true
toc_depth: 3
number_sections: true
This should add the title before your TOC. You can do other modifications, e.g. change from h1
to another tag and/or use the field class on the CSS. If you have problems for not using the default template (mathjax won't work), you can change the default style, not adding totctitle
to a different rmd file later shouldn't be a problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With