4

I'm building a bookdown::html_document2 with Rstudio and I can't seem to manage to add a table of content using Rstudio.

I've found this question (Bookdown: TOC with html_document2) that is related however I knit my document using the Knit button of Rstudio while they are using a command line. In my case, it produces the error:

Error in yaml::yaml.load(string, ...) : 
  Scanner error: mapping values are not allowed in this context at line 4, column 33
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load_utf8 -> <Anonymous>
Execution halted

To reproduce the error, try:

---
title: "main title"
author: "Me"
date: "September 26, 2018"
output: bookdown::html_document2:
  toc=TRUE
---


# title 1

# tt

# rr 

## rrr

in Rstudio and hit Knit

Any idea how to make it work? Thanks

Bastien
  • 3,007
  • 20
  • 38

1 Answers1

6

Move the bookdown::html_document2: into the next row, and add toc=TRUE underneath it. Be carefull for indendation. Check out the full YAML syntax.

---
title: "main title"
author: "Me"
date: "September 26, 2018"
output:
  bookdown::html_document2:
    toc: true
---


# title 1

# tt

# rr 

## rrr
maycca
  • 3,848
  • 5
  • 36
  • 67
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • 3
    Please consider turning this into more than just a "read the manual" answer. You could have added some context, like "every new output type should be on its own line, after the call to `output`. You also need to be careful with indentations. You can find out more [here](https://bookdown.org/yihui/bookdown/r-markdown.html). This is how you would implement it:...`. – Andy Clifton Oct 20 '19 at 12:38
  • @AndyClifton Excellent suggestion! Please feel free to edit my answer (sometimes I just type out answers in a hurry and I definitely agree with you that this particular answer should be improved). Thank you very much! – Yihui Xie Oct 21 '19 at 03:27
  • oddly hard to find an answer to this question. This answer along with YAML syntax suggestion was perfect – JustGettinStarted Feb 25 '22 at 00:43