How to insert appendix after references in Rmd using Rstudio?
Asked Answered
T

2

9

I am using Rstudio, to create a pdf / html document from an Rmd file. The header looks sth like this:

title: "Title"
author: "Me"
date: "`r format(Sys.time(), '%B %d, %Y')`"
bibliography: bibliography.bib
output:
  html_document:
    toc: true
    number_sections: true

Now, I have some sections, and then include the references. After that, an appendix should follow, but I encounter the exact same problem as described here: Pandoc insert appendix after bibliography

There is a fixed solution in this thread, but I have no idea how I can do that within RStudio directly. To get the document, I just press the "Knit html" button, and do not run any pandoc commands myself. So where should I put the

--include-after-body

part, and how should the appendix rmd file look like?

Tailspin answered 15/10, 2015 at 12:16 Comment(0)
P
8

As noted in the rmarkdown manual, you could use this syntax:

---
output:
  html_document:
    includes:
      after_body: appendix.md
---

This is equivalent to the general way to add arbitrary pandoc arguments to a Rmd file:

---
output:
  html_document:
    pandoc_args: ["--include-after-body=appendix.md"]
---
Proliferous answered 6/11, 2015 at 16:49 Comment(4)
You can also add pandoc flags / options that are not covered by the yaml syntax. This is discussed in here: #16428137. It seems like the R markdown folks have introduced after_body includes lately or it is not well known. However, it might just be a more flexible (but more complicated) alternative.Shareeshareholder
You are right, I wasn't technically answering the OP's question about where to add a pandoc argument and it might be useful. I tend to prefer Rmd YAML options when they exist though, as they usually look better.Proliferous
what if i am kniting a pdf document, how do I do thisShambles
@Shambles the same solution should work, just replace html_document with pdf_documentProliferous
W
3

The following might be easier; works if you knit to PDF, Word or HTML:

Everything I wanted to say in the main document.

# References

<div id="refs"></div>

\newpage
# Appendix

Some details that will bore the readers of the main document.

In the original post, this was also posted as an answer (few years after current question was asked): see https://mcmap.net/q/434925/-pandoc-insert-appendix-after-bibliography and https://mcmap.net/q/434925/-pandoc-insert-appendix-after-bibliography

Wilinski answered 6/12, 2021 at 12:11 Comment(3)
Great solution. Clean and simple and also works in Quarto!Idiocrasy
Very useful to contain source in one file only.Frictional
This no longer seems to work for me :(. The references are still appended after the appendix.Condominium

© 2022 - 2024 — McMap. All rights reserved.