Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add table of contents in HTML output of knit /Rstudio

What are possible ways of adding table of contents in html output of knitr::knit2html()?

I am familiar with the markdownHTMLOptions solution. However the result is not the good-looking one? For me it is important to have such table of contents so that it follows the webpage while scrolling and i could possibly navigate anytime I want.

like image 334
kuba Avatar asked Dec 04 '25 14:12

kuba


1 Answers

A floating table of contents is now supported by Rmarkdown! It moves with you as you scroll, you click to navigate... such an improvement :)

The directions are very good: http://rmarkdown.rstudio.com/html_document_format.html

In short, add this at the top of your rmd script, where toc stands for table of contents, and float means that it stays visible on the left as the page scrolls:

---
title: "Bla"
output:
  html_document:
    toc: true
    toc_float: true
---
like image 200
rrr Avatar answered Dec 06 '25 08:12

rrr