Rmarkdown: remove some headers from TOC - r

This is a follow up question to this. I'd like to put a header within a {.tabset} that does not get referenced by the TOC or break the tabbing. For example:
---
output:
html_document:
toc: true
toc_float: true
---
# Tabset 1 {.tabset}
## A
Text under tab A
<h1>Don't want this in TOC</h1>
## B
Text under tab B
Produces this:
Is there anyway to format text like a header but not have it referenced in the TOC?

Going by the comments there already seems to be an issue dealing with this particular problem.
However, a simple workaround would be to use a normal <p> tag but style it like a header. So for your particular example you could do the following:
---
output:
html_document:
toc: true
toc_float: true
---
# Tabset 1 {.tabset}
## A
Text under tab A
<p style="font-weight:600; font-size:36px">Paragraph that looks like a header.</p>
## B
Text under tab B
According to this link a value of 600 for font-weight qualifies as semi-bold which is what Bootstrap seems to be using for their <h1> headers.

Related

Modifying rmdformats::robobook to display pages by header level

I am using rmdformats::robobook as my format for an r-markdown document. While I like the depth of the TOC for that template, I dislike the continuous scrolling. I prefer how rmdformats::material only allows you to scroll as far as the 1st level header / starts a new page for each h1 (but I dislike that I can't increase the depth of the TOC).
So, my question: Is there a simple way to modify or an argument in the yaml that would tell it to make a new page by some level of header (e.g. just h1 or h1 and h2, but not h3)? I guess similar to how the TOC and page display in R Markdown: the Definitive Guide function (I could not find that available as a template).
Reproducible code:
---
title: "tmp"
output:
rmdformats::robobook:
toc_depth: 2
toc_float:
collapsed: FALSE
use_bookdown: TRUE
---
# Section 1
`r OpenRepGrid::randomWords(250)`
## Subsection 1
`r OpenRepGrid::randomWords(250)`
### not in TOC
`r OpenRepGrid::randomWords(250)`
# Section 2
`r OpenRepGrid::randomWords(250)`
## Subsection 2
`r OpenRepGrid::randomWords(250)`
### not in TOC
`r OpenRepGrid::randomWords(250)`

How to indent numbered sections and subsections in R Markdown (bookdown)?

I know how to indent text such as bullets and numeric lists, but I am also interested in indenting numbered sections and subsections as well. Given the following code, it renders to the screen shot following the code. The table of contents has subsections indented and I would like to indent the content body as well.
Is there a way to indent the subsections in the body of the document as well? See the Desired Output Example item afterwards.
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 6
number_sections: true
---
# Section A
## Level 2 A
### Level 3 A
#### Level 4 A
## Level 2 A
# Section B
## Level 2 B
Rendered without indented subsections
Desired Output Example
... table of contents as above ...
1 Section A
1.1 Level 2 A
1.1.1 Level 3 A
1.1.1.1 Level 4 A
1.2 Level 2 A
2 Section B
2.1 Level 2 B
EDIT: 2021-12-15
The solution for this by #Peter worked for me on the Mac but required a workaround for the Linux system I am using. I found the issue with the solution not working on my Linux machine was the result of a bug in version 2.10 of titlesec (which is what I have). The fix can be either to update titlesec or use a workaround; both are described in this link: titlesec: loss of section numbering with the new update (2016/03/15)
Not entirely sure if it is the heading in the table of contents (toc) or or the headings in the body of the document that want to be indented.
You can indent the headings in the text using the latex titlesec package and the titlespacing command (as originally posted, then deleted following comments from #manro).
However, this only works for the first three levels out of the box, which in latex-land are generally considered enough. Updated comment #manro has found a solution to this.
Indentation in the toc is more straight forward: its a case of getting the correct indentation for the yaml commands...
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 6
number_sections: true
header-includes:
- \usepackage{titlesec}
---
\titlespacing{\section}{0pt}{*4}{*1.5}
\titlespacing{\subsection}{20pt}{*4}{*1.5}
\titlespacing{\subsubsection}{40pt}{*4}{*1.5}
\titlespacing{\subsubsubsection}{60pt}{*4}{*1.5} # does not work
# Section A
## Level 2 A
### Level 3 A
#### Level 4 A
## Level 2 A
# Section B
## Level 2 B
I don't know, but in
bookdown::pdf_document2:
... toc_depth can be only max = 2.
Maybe, it is a bug? Or I did something wrong?
But, for
output: pdf_document
... we can make this solution (Peter, I remember your contribution!)
---
title: "Toc is Toc"
header-includes:
- \usepackage{titlesec}
output:
pdf_document:
latex_engine: lualatex
toc: yes
number_sections: yes
toc_depth: 4
documentclass: article
---
\titlespacing{\section}{0pt}{*4}{*1.5}
\titlespacing{\subsection}{20pt}{*4}{*1.5}
\titlespacing{\subsubsection}{40pt}{*4}{*1.5}
\titlespacing{\paragraph}{60pt}{*4}{*1.5}
\section{I don't know}
\subsection{Why}
\subsubsection{In bookdown}
\paragraph{TocDepth is only two}
P.S. Mr. Yihui Xie, can you shed light on this case? Thanks ;)

Remove section number from main text and from Table of Content

In Rmarkdown (output = PDF), if I add {-} to the section it removes the number, but it still shows in the TOC. How to do if I don't want it to show in the TOC?
thank you
I'm not sure exactly what you're asking, but hopefully one of these will do the job.
---
title: "Test"
author: "Test"
date: "Today"
output:
pdf_document:
toc: true
number_sections: true
---
# First
Number and title appear in TOC.
# Second {-}
Title appears in TOC.
\section*{Third}
Nothing appears in TOC.

Number some sections with rmarkdown

I am writing a manuscript with rmarkdown.
If I want to number all sections, I can use YAML like this
---
title: "My Report"
output:
html_document:
number_sections: true
---
See Automatically number sections in RMarkdown
But I only want to number some sections, so my document looks like
Abstract
1. Introduction
2. Methods
3. Results
References
Is there anyway to do this?
From the Pandoc User Guide you want to add the .unnumbered attribute to the header. This is done using:
# My header {.unnumbered}
or the shortcut
# My header {-}
For example, using the following document
---
title: "My Report"
output:
html_document:
number_sections: true
---
# Abstract {-}
# Introduction
# Methods
# Results
# References {-}
The HTML produced renders as:

rmarkdown Table of Contents not being populated

I have a simple test .Rmd script which I am using to generate a PDF file with the rmarkdown render function.
When I set the toc to be true, the second PDF page is a blank white page and I would expect to see 'Slide With Bullets' and 'Slide with R Code and Output' to be in there.
Does anyone know how to format the slide titles so that they appear in the table of contents?
---
title: "test"
author: "test"
date: '2015-10-29'
output: beamer_presentation
toc: true
---
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
## Slide with R Code and Output
```{r}
summary(cars)
```
According to the documentation toc only works with level 1 headings. So the code below will create a table of contents to the title slide. I can't get it to work with slides that contain content though. Maybe this is how the table of contents is designed to work???
---
title: "Untitled"
output:
beamer_presentation:
toc: yes
---
# A Title Slide:
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
## Slide with R Code and Output
```{r}
summary(cars)
```

Resources