如何在 Rmarkdown/pandoc 中抑制自动数字编号 [英] How to suppress automatic figure numbering in Rmarkdown / pandoc
问题描述
我有以下 Rmarkdown (.Rmd) 文档,我在其中调用现有的 .png 图像并创建带有标题的 .pdf.默认情况下,pandoc?正在自动添加图#".在每张图片的标题之前.我可以看到这是正常的事情,但在我的情况下,我想定义它.我发现了有关此主题的变体,但似乎没有找到解决方案.下面是我的 .Rmd 文件外观示例:
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)
推荐答案
你可以使用 caption-package
You could use the caption-package
创建一个 .tex 文件,在其中指定以下内容,下面删除整个标签,您可以自由地对标签进行硬编码.
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}
那么你的 .rmd 应该是这样的:
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)
简化:正如评论中所建议的,我们可以在我们的 .Rmd
文件中实现这一点,如下所示.
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)
这篇关于如何在 Rmarkdown/pandoc 中抑制自动数字编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!