I am writing a report with R Markdown in which I include references. The problem is that R markdown automatically places references at the end of the report. I would like to place an Appendix after the references, is there a way to do it? I saw that it is possible with a child document but I would like to have everything in a unique .Rmd file.
Below is a reproducible example:
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
---
# Partie 1
\cite{greenwood_financial_1989}
<!-- where I would like the references to be -->
# Appendix
bla bla
and here is the content of the references.bib file:
#article{greenwood_financial_1989,
title = {Financial Development, Growth and the Distribution of Income},
url = {https://www.nber.org/papers/w3189},
number = {3189},
journaltitle = {NBER Working Paper Series},
date = {1989},
author = {Greenwood, Jeremy and Jovanovic, Boyan}
}
Any idea ?
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
If using
citation_package: biblatex
you can include the bibliography at an arbitrary point using
\printbibliography
This does not, of itself, stop pandoc adding a (further) end-of-document bibliography, but since pandoc ignores latex in non-latex output, we can suppress that by redefining \printbibliography on the fly to do nothing.
So try this, for a references section preceding an Appendix:
# References
<div id="refs"></div>
\printbibliography[heading=none]
\def\printbibliography{}
# Appendix 1
Appendix goes here, and is not followed by a bibliography.
Related
I wonder if it is possible to put an appendix after references when using biblatex. These question and answer or this answer showed how to do so without citation_package: biblatex but do not work anymore when I add this in YAML. Using child document to print appendix after references does not work either.
Is it possible to use both biblatex and this solution?
Here's a reproducible example (Not working. Remove citation_package: biblatex for a functional example):
---
title:
author:
date:
abstract:
output:
pdf_document:
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
---
# Part 1
#greenwood_financial_1989
# My references
<div id="refs"></div>
# Appendix
bla bla
with references.bib:
#article{greenwood_financial_1989,
title = {Financial Development, Growth and the Distribution of Income},
url = {https://www.nber.org/papers/w3189},
number = {3189},
journaltitle = {NBER Working Paper Series},
date = {1989},
author = {Greenwood, Jeremy and Jovanovic, Boyan}
}
Edit: As suggested, I compared the latex document produced by the .Rmd file (by adding keep_tex: true in YAML) when I use citation_package: biblatex and when I don't.
I renamed the section "References" as "My references" in the .Rmd file to be able to distinguish the two sections in the latex document.
It appears that:
using citation_package: biblatex automatically adds \printbibliography at the end of the latex document, hence the "References" section with the actual references at the end of the PDF output. Besides, the section "My references" only contains \hypertarget{refs}{}.
when I remove citation_package: biblatex, the \printbibliography line disappears from the latex document, and the "My references" section contains \leavevmode\hypertarget{}{} with the id of the reference and its full description (that I do not paste here because it would only make this less readable).
Therefore, I guess this problem appears during the conversion from the .Rmd file to .tex format.
I am writing a report with R Markdown in which I include references. The problem is that R markdown automatically includes references at the end of the report (without calling them with \printbibliography for example) and the section title is "References". I am writing in French so I would like the title to be "Références", but more generally is there any way to modify the title of that section?
Below is reproducible example:
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
---
# Partie 1
\cite{greenwood_financial_1989}
# Partie 2
bla bla
and here is the content of the references.bib file:
#article{greenwood_financial_1989,
title = {Financial Development, Growth and the Distribution of Income},
url = {https://www.nber.org/papers/w3189},
number = {3189},
journaltitle = {NBER Working Paper Series},
date = {1989},
author = {Greenwood, Jeremy and Jovanovic, Boyan}
}
Does anybody have a solution?
Here's the solution that combines this answer on doing something similar with bibtex and this one on the TeX required to do it in biblatex, plus #Ralf's comment about adding lang: fr
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
lang: fr
---
In my document, I used :
header-includes:
- \usepackage[french]{babel}
And your Contents section also changes.
I had a similar problem I wanted to place the bibliography above a supplemental section and placing <div id = "refs"></div> where you want the references successfully repositioned the section. I also had no problem renaming the section by simply changing the # title above that section. This did work for PDF output as well as HTML despite appearing to be an HTML only solution, though I was also using the markdown flavored ([#Smith2019]) references in the body of my document I don't know if using the LaTeX style will affect things.
When citation_package: biblatex is included in the YAML of an .Rmd file, is it possible to specify the citation style? I can't find any information on this in the various R markdown manuals.
This issue was resolved in March 2016. As a lot of the documentation was written before this, it doesn't always show up in the guidance. However, the NEWS file on rmarkdown is always a good place to check for new features.
You can use the biblio-style argument within the YAML. If you are familiar with latex, this is basically filling in the \usepackage[style= *SELECTED STYLE*]{biblatex}. Here is an example. It will build a separate .bib file for you:
---
output:
pdf_document:
citation_package: biblatex
keep_tex: TRUE
bibliography: test.bib
---
```{r}
knitr::write_bib(x = c("knitr", "rmarkdown") , file = "test.bib")
```
Some ref [#R-knitr]
Another ref [#R-rmarkdown]
# References
This outputs:
Adding the biblio-style argument:
---
output:
pdf_document:
citation_package: biblatex
keep_tex: TRUE
bibliography: test.bib
biblio-style: authoryear
---
```{r}
knitr::write_bib(x = c("knitr", "rmarkdown") , file = "test.bib")
```
Some ref [#R-knitr]
Another ref [#R-rmarkdown]
# References
To find out more about different styles you can use, check here: https://www.sharelatex.com/learn/Biblatex_citation_styles
Taking this further: the YAML only provides a certain amount of control of the biblio-style. For example, you cannot specify citestyle directly. if you want to go further with changing the biblatex style, you will need to edit the pandoc template: https://github.com/rstudio/rmarkdown/blob/master/inst/rmd/latex/default-1.15.2.tex . This is a bit more advanced though, so only recommend it if you are comfortable with LaTex: https://rmarkdown.rstudio.com/pdf_document_format.html#custom_templates
Input data
I prepared an example Rmd file with references to figure, table and equation, setting as an output 'bookdown::pdf_document2'. It compiles without errors to PDF.
I placed it on dropbox:
https://www.dropbox.com/sh/zmu0a4wq95ywssv/AAD-nHlkDiLknLk2NVR4Xup3a?dl=0
Question
Now I wish to set as an output format 'rticles::elsevier_article'
How can I do that?
Issue
When I change output line from:
bookdown::pdf_document2
to
rticles::elsevier_article
I'm receiving an error message.
Even if I remove other parameters from output:
I still receive an error message:
! Undefined control sequence.
Accented characters when input "as is" do not appear to behave well with elsevier_article. See suggestions below.
Bare-bones document
Here is a bare-bones document using rticles::elsevier_article:
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
Hello world.
which renders with no complaints:
Reference with accents
Now, we wish to add a reference with accents. We follow the answer here: https://tex.stackexchange.com/questions/57743/how-to-write-%C3%A4-and-other-umlauts-and-accented-letters-in-bibliography. I imported your bibliography into Zotero, and then exported the item with a "Central European (ISO)" encoding (not UTF-8) to obtain
#article{kedzior_this_2018,
title = {This is sample title only {\k A} {\L }},
volume = {99},
url = {http://megooglethat.com/},
journal = {Some journal},
author = {K{\k e}dzior, Mateusz and {\'Z}{\k e}{\'n}, {\.Z}{\k a}{\'c}{\l }},
year = {2018},
keywords = {keywordC},
pages = {21 -- 31}
}
The R Markdown document now becomes
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
biblio-files: bibliography2.bib
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
## Citations and references
Let me cite an article: [#kedzior_this_2018]
# References
I then knited this in RStudio, but realised that I had to get the tex output and rebuild it (outside of RStudio) to get the desired output
Other problems
For accented characters in figure captions, encode them accordingly (as with the bibliography). You may find http://w2.syronex.com/jmr/latex-symbols-converter helpful. In addition, to the best of my knowledge bookdown style cross-referencing does not work with rticles. If you have follow-up questions, you may get more helpful answers if you break your question down into smaller chunks.
I've added a bit of updated material to the commenthttps://github.com/rstudio/rticles/issues/92#issuecomment-402784283 where it states (may be updated):
output:
bookdown::pdf_document2:
base_format: rticles::elsevier_article
number_sections: yes
such that the way I've had this work is using pdf_book versus pdf_document2:
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
number_sections: yes
This allows for figure and table referencing within an rticles document.
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?
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"]
---
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://stackoverflow.com/a/44294306/8234333 and https://stackoverflow.com/a/16428699/8234333