How to add table of contents in Rmarkdown?
The syntax is
---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---
in the documentation. Make sure this is at the beginning of your document. Also make sure your document actually has headers otherwise R can't tell what you want in the table of contents.
How can I add a table of contents in R Markdown?
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
How can I control the location of the table of contents in R Markdown (PDF output)?
If the first two pages shoud contain static content (not generated in the body of the R Markdown document), then moving the table of contents to page 3 can be achieved with small modifications in the LaTeX template used by Pandoc.
As explained in The Cookbook, the default LaTeX template is this (latest version).
Download that file and save it in the directory of your RMD file. In my example below I named the file
toc-at-page3-template.tex
.Edit the template: For example, after line 476 (i.e., before
$if(toc)$
), add\begin{center}
Custom Stuff
\end{center}
\clearpage
\begin{center}
More Custom Stuff
\end{center}
\clearpageIn your RMD file, enable the custom template:
output:
pdf_document:
toc: true
template: toc-at-page3-template.tex
---
Foo.
Output:
(click on thumbnails to enlarge)
Related Topics
Remove/Collapse Consecutive Duplicate Values in Sequence
How to Add a General Label to Facets in Ggplot2
Why Does Unlist() Kill Dates in R
Missing Legend with Ggplot2 and Geom_Line
Split Text String in a Data.Table Columns
Split Up a Dataframe by Number of Rows
Define $ Right Parameter with a Variable in R
Function to Calculate Geospatial Distance Between Two Points (Lat,Long) Using R
Dplyr Mutate with Conditional Values
Remove All Punctuation Except Apostrophes in R
Performing Dplyr Mutate on Subset of Columns
Options for Caching/Memoization/Hashing in R
Get Values and Positions to Label a Ggplot Histogram
Subtract a Column in a Dataframe from Many Columns in R
Creating a Prompt/Answer System to Input Data into R
In 'Knitr' How to Test for If the Output Will Be PDF or Word