7

I'm currently writing a small report in German. Hence I want my figure caption titles to be changed from Figure 1 to Abbildung 1 and so on.

---
title: "Untitled"
author: "me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
  pdf_document: default
---


```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```

Question: How can I change the default figure title (not sure if it's actually called that way) in R Markdown?

andschar
  • 3,504
  • 2
  • 27
  • 35
  • 1
    Some nice tips in the answers here: https://stackoverflow.com/questions/31182147/suppress-automatic-table-name-and-number-in-an-rmd-file-using-xtable-or-knitr – vestland Aug 19 '17 at 11:04

2 Answers2

7

If you are writing in any language other than English, you can change the language options of the outputted pdf with the lang YAML option. This will override all the captions, labels, table of contents etc.

---
output: pdf_document
lang: de
---

```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```

enter image description here

Other language options include fr (French), it (Italian) etc. See http://pandoc.org/MANUAL.html#language-variables for more details.

Michael Harper
  • 14,721
  • 2
  • 60
  • 84
  • 1
    You may get a Package babel Error if the language is not install. Apt install packages starting with "texlive-lang-" on Debian/Ubuntu to install new languages. – Paul Rougieux Nov 26 '20 at 15:09
4

Following the example from this question, you can define your own tex file where you can change figure caption defaults.

header.tex:

\usepackage{caption}
\captionsetup[figure]{name=Abbildung}

This is the main .Rmd file:

---
title: "Untitled"
author: "me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output: 
  pdf_document:
    includes:
      in_header: header.tex
---


```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • @andrasz you may need to learn some rudimentary syntax if you wish to modify pdf output. See tex.stackexchange.com for more info. – Roman Luštrik Aug 19 '17 at 11:48
  • @RomanLuštrik: Is it also possible to print Abbildung 1 in italics? Note that I include the 1 as well. Because afaik apa6h style wants the following: _Figure 1._ Some figure caption – Jaynes01 May 26 '18 at 11:05
  • Never mind. I found it: Just use this captionsetup: `\captionsetup[figure]{name=Figure,labelfont=it,labelsep = period}` – Jaynes01 May 26 '18 at 11:24
  • @Jaynes01 please search for the answer or ask a new question. – Roman Luštrik May 26 '18 at 12:35