I want to change the bibliographystyle
in R Markdown but nothing I found could help.
I do not want any "and"s in the bibliography (before the last author).
My preferred option was if I could use alphadin
(bst-file here) but I could not get it to work.
Here is my YAML so far:
---
output:
pdf_document
bibliography: literatur.bib
biblio-style: alphadin.bst
header-includes:
- \usepackage{graphicx}
- \usepackage{float}
- \usepackage[ngerman]{babel}
- \usepackage{fancyhdr}
- \usepackage{hyperref}
- \pagenumbering{gobble}
- \usepackage{booktabs}
- \usepackage{natbib}
---
The bst-file is in the same directory as the R Markdown file.
If you want to set the bibliography style to use a bst file, you need to force R Markdown to use natbib
or biblatex
as the citation manager. By default, it will use pandoc to build the citation. This article explains the behaviour more.
Secondly, once you have that working, you need to change the citation style of the file. By default, natbib will use author-year citations, but the bst file you provided does not work with these. So I have change the citation styles to numbers.
Below is a minimal example. It will create a bibliography file test.bib
but you need to make sure the alphadin.bst file is in the same directory.
---
output:
pdf_document:
citation_package: natbib
bibliography: test.bib
biblio-style: alphadin
header-includes:
- \setcitestyle{numbers}
---
[@R-rmarkdown]
```{r}
knitr::write_bib(x = "rmarkdown", file = "test.bib")
```
There is another way to set the citation style of natbib: natbiboptions: round
in YAML. The combination of citation_package: natbib
and natbiboptions: round
is equivalent to \usepackage[round]{natbib}
. Note that natbiboptions: round
comes outside of the output
key.
(In the following example, I used biblio-style: apalike
but the example should work with any biblio-style
.)
---
output:
pdf_document:
citation_package: natbib
bibliography: test.bib
biblio-style: apalike
natbiboptions: round
---
[@R-rmarkdown]
```{r}
knitr::write_bib(x = "rmarkdown", file = "test.bib")
```
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