13

I have the following Rmarkdown (.Rmd) document where I call existing .png images and create a .pdf with captions. By default, pandoc? is automatically adding "Figure #." before the caption for each picture. I can see how this would be the normal thing to do, but in my case I would like to define this. I have found variations on this topic but don't seem to find a solution. Below is an example of how my .Rmd file looks:

---
title: "TITLE"
author: "ME"
date: "`r Sys.Date()`"
output: 
  pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

![Caption for figure 1](figures/plot1.png)


\newpage

![Caption for figure 2](figures/plot2.png)
Marc in the box
  • 11,769
  • 4
  • 47
  • 97

1 Answers1

16

You could use the caption-package

Create a .tex-file that you specify the following in, this below remove the entire label and you are free to hardcode the labels.

\usepackage{caption}
\captionsetup[figure]{labelformat=empty}

Then your .rmd should look like this:

---
title: "TITLE"
author: "ME"
date: "`r Sys.Date()`"
output: 
  pdf_document:
    includes:
      in_header: YourName.tex
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

![Caption for figure 1](figures/plot1.png)

\newpage

![Caption for figure 2](figures/plot2.png)

Simplified: As suggested in the comments, we can achieve this within our .Rmd file, as shown below.

---
title: "TITLE"
author: "ME"
date: "`r Sys.Date()`"
output: 
  pdf_document:
header-includes:
- \usepackage{caption}
- \captionsetup[figure]{labelformat=empty}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

![Caption for figure 1](figures/plot1.png)

\newpage

![Caption for figure 2](figures/plot2.png)
Megatron
  • 15,909
  • 12
  • 89
  • 97
ErrantBard
  • 1,421
  • 1
  • 21
  • 40
  • 3
    Just found out that the lines of YourName.tex can be put directly in the starting lines: `header-includes: \usepackage{caption} \captionsetup[figure]{labelformat=empty}` – Marc in the box Mar 17 '17 at 09:27
  • @Marcinthebox Nice! In most of my own reports I do quite a bit of latex non-default stuff but for those times were you just use the odd package that's much simpler – ErrantBard Mar 17 '17 at 10:08
  • 1
    thanks a lot @Marcinthebox, I had looked for this for quite long – splaisan Dec 14 '18 at 15:30
  • 1
    To suppress the autolabeling for tables, add another line in the YAML swapping out "table" for "figure": - \captionsetup[table]{labelformat=empty} – mikoontz Apr 15 '19 at 16:47