Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the caption title of a figure in markdown

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?

like image 451
andschar Avatar asked Aug 19 '17 10:08

andschar


2 Answers

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.

like image 128
Michael Harper Avatar answered Sep 23 '22 03:09

Michael Harper


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

like image 22
Roman Luštrik Avatar answered Sep 22 '22 03:09

Roman Luštrik