1

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?

deschen
  • 10,012
  • 3
  • 27
  • 50

1 Answers1

3

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"

jmcastagnetto
  • 441
  • 2
  • 7