Pandoc insert appendix after bibliography
Eventually reference handling will change to make it possible to put the references wherever you like (https://github.com/jgm/pandoc/issues/771), but right now there's no easy way to do it.
As suggested here, you could put your appendix in a separate file, use pandoc to convert it to a LaTeX fragment, then include that fragment using the --include-after-body
flag. It would then come after the bibliography.
R Markdown: place an Appendix after the References section?
This is explained in the R Markdown Cookbook (section 3.5.4). We can force the bibliography to be printed at a particular place with:
# References
<div id="refs"></div>
# Appendix
Note that:
- this works if we cite the papers with
@id_of_paper
(which is the recommended way in R Markdown) but not with\cite{id_of_paper}
. - this does not work if we use
citation_package: biblatex
in YAML
Here's my adapted example:
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
bibliography: references.bib
biblio-style: bwl-FU
---
# Partie 1
@greenwood_financial_1989
# References
<div id="refs"></div>
# Appendix
bla bla
Adding figures and tables after bibliography in Rmarkdown
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
Include Rmd appendix after references
In order to have appendices after the references, you simply include a div with id="refs" which tells pandoc where to include the references section. For example:
```{r, child = "08_discussion.Rmd"}
```
# References
<div id="refs"></div>
```{r, child = "09_appendix.Rmd"}
```
Credit: https://twitter.com/tjmahr/status/763435602935095296
Pandoc: Is there a way to include an appendix of links in a PDF from markdown?
This is something that is easy to achieve with filters.
Here is linkTable.hs
. A filter which adds a table of links to the end of your document.
import Text.Pandoc.JSON
import Text.Pandoc.Walk
import Data.Monoid
main :: IO ()
main = toJSONFilter appendLinkTable
appendLinkTable :: Pandoc -> Pandoc
appendLinkTable (Pandoc m bs) = Pandoc m (bs ++ linkTable bs)
linkTable :: [Block] -> [Block]
linkTable p = [Header 2 ("linkTable", [], []) [Str "Links"] , Para links]
where
links = concatMap makeRow $ query getLink p
getLink (Link txt (url, _)) = [(url,txt)]
getLink _ = []
makeRow (url, txt) = txt ++ [Str ":", Space, Link [Str url] (url, ""), LineBreak]
Compile the filter with ghc linkTable.hs
. The output is as follows.
> ghc linkTable.hs
[1 of 1] Compiling Main ( linkTable.hs, linkTable.o )
Linking linkTable ...
> cat example.md
Title
-----
[Python][] is cool!
[Pip] is a package manager.
...
[Python]: http://python.org
[Pip]: https://pip.readthedocs.org
Then running pandoc
with the filter.
> pandoc -t markdown --filter=./linkTable example.md
Title
-----
[Python](http://python.org) is cool!
[Pip](https://pip.readthedocs.org) is a package manager.
...
Links {#linkTable}
-----
Python: <http://python.org>\
Pip: <https://pip.readthedocs.org>\
Related Topics
Multiple Boxplots Using Ggplot
How to Extract All the Rows If a Level in One Column Contains All the Levels of Another Column in R
Create an Expression from a Function for Data.Table to Eval
Remove Rows Where All Variables Are Na Using Dplyr
How to Preserve Base Data Frame Rownames Upon Filtering in Dplyr Chain
Where Should I Put Data for Automated Tests with Testthat
Check If Each Row of a Data Frame Is Contained in Another Data Frame
Merge Data Frames and Overwrite Values
Plot Causes "Error: Incorrect Number of Dimensions"
R Reading in a Zip Data File Without Unzipping It
Generating a Vector of Difference Between Two Vectors
What Does the Diff() Function in R Do
Differencebetween Names and Colnames