17
votes

I have an rmarkdown document (.Rmd) that I want to knit into a pdf document. number_sections has been put to 'yes' and toc to 'true'. How can I add appendix sections that appear in the table of contents but don't have a section number?

Here is an example .Rmd code. How can I let appendix A and appendix B be numberless sections and let them appear in the table of contents at the same time?

---
title: "Test"
author: "test test"
geometry: margin=1in
output:
  pdf_document:
    keep_tex: yes
    latex_engine: xelatex
    number_sections: yes
    toc: yes
    toc_depth: 3
header-includes:
- \usepackage[dutch]{babel}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot[LE,RO]{this is a fancy foot}
- \usepackage{dcolumn}
- \usepackage{here}
- \usepackage{longtable}
- \usepackage{caption}
- \captionsetup{skip=2pt,labelsep=space,justification=justified,singlelinecheck=off}
subtitle: test test test
fontsize: 12pt
---
# start

# second

```{r results="asis",eval=TRUE,echo=FALSE,message=FALSE, error=FALSE, warning=FALSE, comment = NA,fig.height=4}
cat("and here some R")
```

# appendix A

# appandix B
1
do you mean you want them lettered rather than numbered? Can you show how you want the table of contents to look?Ben Bolker
@BenBolker, no I don't want them to be lettered. I already have an answer, but I understand your question. Next time I will try to make a prefered outcome as well.rdatasculptor

1 Answers

28
votes

Just add {-} after the section name. Thus, for your appendices, you should do something like:

# appendix A {-}

# appendix B {-}

For more details, see this section of the docs.


Result:

enter image description here