How to add table of contents in any place using pagedown package template?

304 Views Asked by At

I used the code from thesis template of pagedown package. The default position of table of contents is after Acknowledgement and before List of table. I would like to add it after the Literature Review section. How can I do it?.

This is the code from the pagedown package's thesis template. You can install it: remotes::install_github('rstudio/pagedown')

---
title: A paged html thesis template for R Markdown users
subtitle: A {pagedown} template.
author: 
  - name: William Brent Thorne
    edu: BSc
degree: Master of Documentation
institute: Typeset University
faculty: Reproducibility and FOSS
department: Templates
location: St. Catharines, ON 
date:
  - year: 2019
    month: August
sign_page: true
dedication: A dedication line or two goes here.
abstract: This is the abstract.
preface: A preface to the thesis.
acknowledge: Put the ackknowledgements here.
committee:
  - name: Jane Doe III
    prefix: Dr
    position: Chair of Department
  - name: John Smith
    prefix: Dr
    position: Faculty Advisor
lof: true
lot: true
toc-title: Contents
output:
  pagedown::thesis_paged: 
    toc: true
    number_sections: yes
    pandoc_args: --mathjax
    self_contained: no
bibliography: packages.bib
link-citations: yes
# uncomment this line to produce HTML and PDF in RStudio:
knit: pagedown::chrome_print
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
                      fig.align = 'center')
```

# Literature Review {-}

This is where you can include a lit review if you don't wish for it to be an individual chapter or to be numbered. To make sure that a section heading is not numbered use the `{-}` notation beside the header text like this:

_**rmarkdown**_:

```markdown
# Literature Review {-}

This is where you can include a lit review if you don't wish for it to be an individual chapter or to be numbered. To make sure that a section heading is not numbered use the `{-}` notation beside the header text like this:
```

# The Basics {.chapter}

## Introduction

This template is based on the `pagedown::html_paged` template and modified to meet the requirements of a generic thesis document. Standard RMarkdown formatting can be used for smooth and distraction free writting, for example I will add a citation for the {knitr} package which is located in the `Thesis.bib` file auto-generated in this template [@R-knitr].

Thanks to the [help](https://github.com/rstudio/pagedown/issues/101) of [Romain Lesur](https://github.com/RLesur) this template has the ability to tag section headers with the word "Chapter ". To have your chapters display as this one (_Chapter 1 The Basics_) use the `{.chapter}` class like this:
1

There are 1 best solutions below

1
On

Using this LINK I was able to get a table of contents to render after the Literature Review section. You will have to remove the table of contents parts of your yaml header I believe. enter image description here

Here is my table of content .Rmd file

---
output: html_document
---

# Table of contents
## literature review
## literature review

And then here is your code with the link resource I used to get it to render in another .Rmd file

---
title: A paged html thesis template for R Markdown users
subtitle: A {pagedown} template.
author: 
  - name: William Brent Thorne
    edu: BSc
degree: Master of Documentation
institute: Typeset University
faculty: Reproducibility and FOSS
department: Templates
location: St. Catharines, ON 
date:
  - year: 2019
    month: August
sign_page: true
dedication: A dedication line or two goes here.
abstract: This is the abstract.
preface: A preface to the thesis.
acknowledge: Put the ackknowledgements here.
committee:
  - name: Jane Doe III
    prefix: Dr
    position: Chair of Department
  - name: John Smith
    prefix: Dr
    position: Faculty Advisor
lof: true
lot: true
output:
  pagedown::thesis_paged: 
    toc: true
    number_sections: yes
    pandoc_args: --mathjax
    self_contained: no
link-citations: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
                      fig.align = 'center')
devtools::source_gist("c83e078bf8c81b035e32c3fc0cf04ee8", 
                      filename = 'render_toc.R')
```

# Literature Review {-}

This is where you can include a lit review if you don't wish for it to be an individual chapter or to be numbered. To make sure that a section heading is     not numbered use the `{-}` notation beside the header text like this:


```{r toc, echo=FALSE} 
render_toc("tableofcontent.Rmd")
```



_**rmarkdown**_:


```markdown
# Literature Review {-}

This is where you can include a lit review if you don't wish for it to be an individual chapter or to be numbered. To make sure that a section heading is     not numbered use the `{-}` notation beside the header text like this:
```

# The Basics {.chapter}

## Introduction

This template is based on the `pagedown::html_paged` template and modified to meet the requirements of a generic thesis document. Standard RMarkdown     formatting can be used for smooth and distraction free writting, for example I will add a citation for the {knitr} package which is located in the     `Thesis.bib` file auto-generated in this template [@R-knitr].

Thanks to the [help](https://github.com/rstudio/pagedown/issues/101) of [Romain Lesur](https://github.com/RLesur) this template has the ability to tag     section headers with the word "Chapter ". To have your chapters display as this one (_Chapter 1 The Basics_) use the `{.chapter}` class like this:    

But your format is very specific so you will have to format it a little better to fit your desired output.