2

I have the following R notebook:

---
title: "test"
author: "by me"
date: 'last updated: Jan 23, 2022'
output:
  html_notebook:
    toc: yes
    toc_float: yes
    number_sections: yes
    highlight: haddock
---

# First headline

## Second headline

```{r}
1:5
```

When I click on "preview", it creates an html document that keeps the TOC on the left side (as expected). When I click on "knit to html", it puts the TOC in the main body of the document. It's still a TOC, but at the wrong place. It also doesn't collapse the individual headlines anymore and instead shows the full ToC.

How can I keep the ToC on the left and keep the headlines collapsed per default?

1 Answer 1

5

When you knit to HTML, in reality knitr is using the definitions for html_document, so if you add the appropriate YAML header, it should work.

---
title: "test"
author: "by me"
date: 'last updated: Jan 23, 2022'
output:
  html_document:
    toc: yes
    toc_float: yes
    df_print: paged
    number_sections: yes
    highlight: haddock
  html_notebook:
    toc: yes
    toc_float: yes
    number_sections: yes
    highlight: haddock
---

# First headline

## Second headline

```{r}
1:5
```

Example of "knit to HTMLE"

Sign up to request clarification or add additional context in comments.

3 Comments

Additionally, you can check bookdown.org/yihui/rmarkdown/notebook.html, for a more in-depth explanation of the notebook format
Thanks, this did the job.
it worked for me too, but I used only the html_notebook: part

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.