How to remove a section from the table of contents? - r

Or in other words: is there something like \tocless for Rmd's? I found something for Latex here, but could not find anything for an Rmd.
Changing toc-depth is not an option:
output:
html_document:
toc: true
toc_float:
collapsed: false
toc_depth: 2
Reproducible example:
---
title: "Untitled"
author: "SQC"
date: "7 Juni 2018"
output:
html_document:
toc: true
toc_float:
collapsed: false
toc_depth: 2
theme: yeti
---
## Sec. 1
bla
## Sec. 2 - not part of content
bla

Though some years have passed since the post of this question, I still want to respond to this question because others may benefit from the answer. If you do not want certain section headings to be included in the table of contents, you can add two classes to the heading: unlisted and unnumbered. For example:
# Section heading {.unlisted .unnumbered}
See here: https://bookdown.org/yihui/rmarkdown-cookbook/toc-unlisted.html

Related

Coloring paragraph section headers

I am trying to color my paragraph section headers but the is not working. Could someone point out why this is not coloring my sections? Consider the example below:
---
title: "number_sections"
output:
pdf_document:
number_sections: yes
toc_depth: 4
toc: true
header-includes:
-\usepackage{color}
- \usepackage{sectsty}
- \allsectionsfont{\color{red}}
---
# Main Section
The above section and the ones below should be red
## 2nd Level
### 3rd Level
# Second Section
## another section
### yet another
#### and the last one please
Your code is pretty much correct, it's just the indentation in the YAML header that's slightly off:
---
title: "number_sections"
output:
pdf_document:
number_sections: yes
toc_depth: 4
toc: true
header-includes:
- \usepackage{color}
- \usepackage{sectsty}
- \allsectionsfont{\color{red}}
---
header-includes should be at the left (not indented), and a missing space before \usepackage

R markdown toc_depth only certain level

in R markdown you can set table of content by this code.
---
title: "Habits"
output:
html_document:
toc: true
toc_depth: 2
---
This way also 1st level of depth is included. I'm curious if there is a way how to set toc_debth ONLY to 2.

How to set position of list of figure (lof) in R bookdown YAML

I have a R bookdown whose YAML looks like this:
---
title: "My title"
toc: False
lof: True
author: "the author"
output:
bookdown::pdf_document2:
keep_tex: yes
---
By default it generates a pdf file with the list of figures at the beginning just after the title.
Is there a way to have this list at the end, after the references?
Remove lof: True and add \listoffigures after your references.

Line spacing for table of contents for bookdown PDF

I am using bookdown in R to create a PDF document. I have specified the line spacing as 1.3 in the index.Rmd which has worked perfectly for the main body of text, including tables, which is fine by me. However, it has not changed the table of contents, or list of figures/tables, which instead have the default spacing. Of course, bookdown generates these additions in the background, so to me it's not straightforward to add raw LeTeX commands to make the change.
My index.Rmd looks like this:
---
title: "This is my book title"
author: "My name"
date: "March 2020"
site: bookdown::bookdown_site
output: bookdown::pdf_book
documentclass: book
description: "Example"
linestretch: 1.3
toc: true
lot: true
lof: true
---
And my _output.yml looks like this:
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
toc_depth: 3
Any advice or suggestions would be greatly appreciated.
I cobbled together an answer from #bretauv's link and another answer on SO - here's the links:
How to change spaces between items in Table of Contents
Chapter(s) before table of contents in Bookdown PDF output
And here's the resulting advice - to reduce line spacing between lines in the table of contents, first tell your .Rmd to NOT create a table of contents in the YAML portion of your .Rmd, e.g.,
---
title: "My title"
output:
bookdown::pdf_document2:
latex_engine: xelatex
toc: FALSE #<--- here's the line you want to ensure says FALSE
fig_caption: yes
mainfont: Arial
fontsize: 10pt
---
Then, the first chunk in your .Rmd can specify that you do actually want to create a TOC, but it tells your .Rmd to change the line spacing for that section (say, 0.7), then change it back to the line spacing you prefer for the rest of your document (say, 1.2). The chunk could look like this:
```{=latex}
% Trigger ToC creation in LaTeX
\renewcommand{\baselinestretch}{0.7}\normalsize
\tableofcontents
\renewcommand{\baselinestretch}{1.2}\normalsize
```
Edit:
In response to #bretauv's answer and to aid in troubleshooting, I'm posting the result of their code on my machine - except I've changed linestretch to 0 and added some body text to show the linestretch is clearly different between TOC and body. Note that one might desire no line spacing between ANY lines - table of contents or body text; however, the linestretch is clearly only applied to the body text. See spacing between entries in the table of contents.
#bretauv, does this happen on your machine with linestretch = 0? Thanks for looking into this with us!
Here's the output if I regroup index.Rmd and my_output.yml in a unique document (I put linestretch:2 just to clearly show that linespacing is applied to the TOC too):
---
title: "This is my book title"
author: "My name"
date: "March 2020"
site: bookdown::bookdown_site
output:
bookdown::pdf_book:
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
toc_depth: 3
linestretch: 2
toc: true
lot: true
lof: true
---
# Section 1
## Subsection 1
## Subsection 2
# Section 2
## Subsection 1
## Subsection 2
# Section 3
## Subsection 1
## Subsection 2
Is this okay? If not, what do you want to change?

Change paper size and orientation in an rmarkdown pdf

I'd like to create a PDF using rmarkdown that is A3 (or 11x17, ideally) and in landscape orientation. I can get it to do one or the other by specifying options in the YAML header, but not both at the same time. Here's my best attempt - the classoption values each work individually, but not together:
---
title: "Test"
output:
pdf_document:
toc: true
number_sections: true
documentclass: article
classoption:
landscape
a3paper
---
This question is related, but doesn't have the answer in this case. Thanks in advance for any help you can provide!
It doesn't seem to be documented, but you can include more than one classoption by separating the options with commas or by using a bulleted list with hyphens. Either of the following will work:
---
title: "Test"
output:
pdf_document:
toc: true
number_sections: true
documentclass: article
classoption:
- landscape
- a3paper
---
---
title: "Test"
output:
pdf_document:
toc: true
number_sections: true
documentclass: article
classoption: landscape, a3paper
---

Resources