RMarkdown: How to change headline in table of contents in R Markdown? - r

When I'm using the toc: yes command, the document contains "Content" as the headline of the table of contents. Due to the fact that I want to write this document in german, I also want to change the headline of the table of contents to the equivalent german word. Any suggestions on how to change this?

This in your YAML should also work:
header-includes:
\renewcommand{\contentsname}{Inhalt}

With this YAML header that includes LaTeX-Package babel, it works for me:
---
title: "TOC in German"
header-includes:
- \usepackage[ngerman]{babel}
output:
pdf_document:
toc: true
number_sections: yes
---

You can also make use of babel simply specifying in the YAML header the "lang" field. For example:
---
lang: de-DE
title: "Ausgefallener Titel"
toc: 1
---
I.e., you can use the "lang" field and specify your desired language-and-country code. For example, de-DE, en-US, etc. (Of course, the corresponding babel package for that language should be installed, or you'll get an error).

Related

R Markdown: change the title of the "References" section?

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.

`bookdown`/`rmarkdown`/`knitr`: YAML header elements dependent on `knitr::opts_knit$get('rmarkdown.pandoc.to')`?

Imagine a bookdown yaml header along the lines of:
---
title: Example
output:
bookdown::pdf_book:
base_format: "function(..., number_sections) rmarkdown::beamer_presentation(...)"
number_sections: yes
bookdown::pdf_document2
geometry: margin=1in, a4paper
---
Compiling this works when using the bookdown::pdf_document2 target, but fails with a \usepackage{caption} option clash for the bookdown::pdf_book target.
I would like to invoke the geometry header entry ONLY for the bookdown::pdf_document2 target, but all experimentation with
!r ifelse(knitr::opts_knit$get('rmarkdown.pandoc.to') %in% c('beamer'), '', 'margin=1in, a4paper')
(with many iterations of ''/NA/'.na'/NULL/'null' etc.) fails, as any empty setting for geometry still interferes.
I also could not find access to the yaml header content from the body of the bookdown/rmarkdown file (aiming to use knitr::opts_knit$set(<SOMETHING>) to modify the header-derived data structure from there).
Yet another option might be to move the top-level parameter geometry below the bookdown::pdf_book or bookdown::pdf_document2 levels - but there appears to be no facility for such overrides at that level.
How would I go about rendering an option like geometry conditional on the output type?

changing rmarkdown "table of contents" default title

I am using RMarkdown to write my MSc thesis, in a language different than English. The thesis shall be rendered in .docx format. Reading around SO, I found that it is possible to provide some pandoc arguments among which toc-title could address my issue. Nevertheless I was not able to do it. My current YAML header is:
output:
word_document:
reference_docx: stile_tesi.docx
toc: yes
fig_caption: true
#pandoc_args: [
# "--toc-title", "INDICE"
#]
Thanks in advance
---
title: "Untitled"
output:
word_document:
toc: yes
toc-title: "INDICE"
---
Important: Watch out the correct indention!

In `_output.yml`, some parameters are getting ignored

I have defined certain pandoc options in _output.yml:
```
author: "abc"
date: "`r format(Sys.time(), '%d %B, %Y')`"
```
But, these get ignored, unless these are defined in the YAML header inside the R Markdown file.
Is this prohibited from including in the separate YAML file? Is so, could you please mention what other parameters should be defined inside the Markdown file.
An _output.yml file can only be used for setting the output formats, as explained within the bookdown book. So you can specify anything which relates to the output format (HTML/PDF/Word) such as:
html_document:
toc: TRUE
theme: flatly
pdf_document:
toc: FALSE
In your examples, the parameters you provide are about document content. So anything like author, title, date, fontsize can't be specified.
This issue has also been addressed within the GitHub issues of R Markdown for further reading.

References Truncated in Beamer Presentation prepared in Knitr/RMarkdown

I'm currently preparing a presentation in RStudio (using RMarkdown and Knitr, outputting to a Beamer presentation) that has quite a few references.
I'm using a pretty typical YAML header:
---
title: "Title"
author: "Me"
date: "February 27th, 2016"
output:
beamer_presentation
csl: ../../apa.csl
bibliography: ../../RefenceDesk.bib
---
This presentation compiles and the references appear as they should, but unfortunately they all appear on one slide (and actually run off the page). Is there any way to have the references appear on multiple slides?
{.allowframebreaks} is the solution for multislides bibliographies in beamer. It works out of the box with regular pandoc templates (see my previous answer). However, knitr has a setting that prevents it, by redefining \widowpenalties in its beamer template. You can verify that if you examine the .tex file with keep_tex: true.
In my opinion, this is a bug. A quick fix would be to reset \widowpenalties to its default value. It can be done in your yaml front matter:
---
title: Title
header-includes:
- \widowpenalties 1 150
output:
beamer_presentation
---
Then, you can indicate the reference section as such:
## References {.allowframebreaks}
As #David above said in the comments:
For me it didnt work with ## References {.allowframebreaks} but it worked out with # References {.allowframebreaks}.
I would like to point out that, apparently for the reference slide to work you have to create a last slide with the same heading level es set by slide_level: __ at the YAML section.
So, the user should set one of the following:
# References {.allowframebreaks}. for those using slide_level: 1, OR
## References {.allowframebreaks}. for those using slide_level: 2, OR
### References {.allowframebreaks}. for those using slide_level: 3 and so on...
While this goes outside of using the regular pandoc citation template, I have found another approach that can be used to put the references across slides but it relies on the natbib citation package.
In the YAML front matter, I added:
---
title: "Title"
output:
beamer_presentation:
citation_package: natbib
bibliography: ../../RefenceDesk.bib
biblio-style: "apalike"
---
The reference slide does not get a title and I cannot seem to adjust the font size (by using a \scriptsize at the end of the .Rmd file), but at least they appear coherently.
EDIT: For parsimony, I removed the csl: ../../apa.csl line, since natbib does not require it.

Resources