Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress automatic figure numbering in Rmarkdown / pandoc

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)
like image 545
Marc in the box Avatar asked Mar 17 '17 07:03

Marc in the box


1 Answers

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)
like image 146
ErrantBard Avatar answered Oct 22 '22 10:10

ErrantBard