Search code examples
rautomationr-markdowntableofcontents

How can I add a table of contents in R Markdown?



I'm having a hard time trying to add a table of contents in R Markdown.
I want the table of contents to be on the left side of the document.
I tried this code, but it didn't work for me (when I knitr the document, it works fine, but the TOC is not available):

---
title: "Relatório VANT - P&D"
author: "Empresa: XXXX"
date: "Data: 24/05/2020"
output: 
  html_document:
  toc: true
  toc_float: true
---

How can I solve my problem?


Solution

  • It is important to indent toc, e.g.

    ---
    title: "Relatório VANT - P&D"
    author: "Empresa: XXXX"
    date: "Data: 24/05/2020"
    output: 
      html_document:
       toc: true
       toc_float: true
    ---
    
    # h1
    
    # h2
    
    # h2.2