I want to add tables and figures after the bibliography in an R Markdown document. However, R Markdown documents will by default always add the bibliography to the end of the report.
Is there an easy way to add content to the document after the references?
A previous answer showed that there is a way to put the appendix after the bibliography in R Markdown. This appendix is a separate file and is added to the document with after_body
in the YAML header. I tried 2 different possible solutions and none of them worked.
results = "hide"
to hide them in the main file. The idea was to create 2 separate PDFs and to merge them. Unfortunately, when the figures are hidden, the references also turn to ??. bookdown:pdf_document2
.R
file and imported into my R Markdown file with include_graphics()
.Upon installing, inserttable registers a new RStudio Addin (Insert Table) that can be used to easily insert a table in a Rmd document. To use it, open a Rmd or R document and select “Addins –> Insert Table”.
The usual way to include citations in an R Markdown document is to put references in a plain text file with the extension . bib, in BibTex format. Then reference the path to this file in index.
You can embed an R code chunk like this: ```{r} summary(cars) ``` You can also embed plots, for example: ```{r, echo=FALSE} plot(cars) ``` Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Rather than trying to include things in the after_body, you are better off just repositioning where the bibliography appears in the document. As explained in this answer, you can choose where the bibliography appears using <div id="refs"></div>
.
Secondly, you can use bookdown to easily add appendices within a document. Using the header # (APPENDIX) Appendix {-}
will change all following secton numbers from numbers to letters. Check out the bookdown book
Used in a full example:
---
title: "Untitled"
output: bookdown::pdf_document2
references:
- id: fenner2012a
title: One-click science marketing
author:
- family: Fenner
given: Martin
container-title: Nature Materials
volume: 11
URL: 'http://dx.doi.org/10.1038/nmat3283'
DOI: 10.1038/nmat3283
issue: 4
publisher: Nature Publishing Group
page: 261-263
type: article-journal
issued:
year: 2012
month: 3
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(magrittr)
```
# Introduction
Here is a citation [@fenner2012a]
# References {-}
<div id="refs"></div>
\newpage
# (APPENDIX) Appendix {-}
# Appendix A
Here is your table
```{r table, fig.pos="H"}
knitr::kable(mtcars[1:5, 1:5], caption = "A table") %>%
kableExtra::kable_styling(latex_options = "HOLD_position")
```
Note: this will only work if you use pandoc's built-in citation package and won't work if you set
citation_package: natbib
in the YAML
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With