I have created a single document with the Bookdown-package of R-Markdown that allows both html- and pdf-output. I would like to change the caption labels Figure
, Table
and Table of Contents
into another language. Here's a minimal example:
---
title: Dokument auf Deutsch
output:
bookdown::html_document2:
toc: yes
bookdown::pdf_document2:
toc: yes
---
# Erstes Kapitel
Abbildung \@ref(fig:pressure) ist Deutsch.
```{r pressure, echo=FALSE, out.width = "80%", fig.pos='h', fig.cap="Deutsche Bildunterschrift"}
plot(pressure)
```
Bookdown uses the English word 'Figure' for the figure caption prefix. When knitting to pdf_document2, Bookdown uses the English word 'Contents' for the toc. How to change these to 'Abbildung' and 'Inhalt'?
I have read section 4.5 Internationalization in the Bookdown manual. The author suggests to edit a configuration file _bookdown.yml
, where one could change the label names. However, I can't find such a configuration file, my single Bookdown-document seems to be self-contained. Also, the example in section 4.5 doesn't indicate how to change the term for the toc.
I found this answer with the \renewcommand
. This works for figures and tables when using output:pdf_document2
, but not with output:html_document2
. As a side issue, \renewcommand{\contentsname}{Inhalt}
doesn't change 'Contents' into 'Inhalt' in the pdf-output. So \renewcommand
is not an ideal workaround.
I would actually like to use the original solution described in the above section 4.5 of the Bookdown manual. Where can I find this configuration file _bookdown.yml
when I write a single Bookdown-document? Where in that file could I change the term for the toc? If I have to first create this configuration file, how exactly should I do that and how can I link it to my single Rmd-document?
If I save your example code as deutsch.rmd
and then render it, I can reproduce what you describe.
If then I create a file called _bookdown.yml
in the same directory as deutsch.rmd
containing
language:
label:
fig: "Abbildung "
and re-render, the word "Figure" is replaced by "Abbildung" in the HTML output.
If then I create a file called preamble.tex
containing
\usepackage[german]{babel}
and adjust the YAML header of deutsch.rmd
to read
title: Dokument auf Deutsch
output:
bookdown::html_document2:
toc: yes
bookdown::pdf_document2:
toc: yes
includes:
in_header: preamble.tex
the PDF output switches to German, too.
edit: I just found out myself, that this solution seems to be equivalent to using the following YAML header:
title: Dokument auf Deutsch
output:
bookdown::html_document2:
toc: yes
bookdown::pdf_document2:
toc: yes
lang: de
Note that the above solution for the PDF output uses "Inhaltsverzeichnis" instead of "Inhalt" though.
If you really want to simply change the figure label and table of contents header to your liking without relying on babel
doing the right thing, you can use the following preamble.tex
instead:
\renewcommand{\figurename}{Abbildung}
\renewcommand{\contentsname}{Inhalt}
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