简体   繁体   English

如何在Rmarkdown / pandoc中抑制自动图形编号

[英]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. 我有以下Rmarkdown(.Rmd)文档,我调用现有的.png图像并创建带有标题的.pdf。 By default, pandoc? 默认情况下,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: 下面是我的.Rmd文件的示例:

---
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)

You could use the caption-package 你可以使用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. 创建一个指定以下内容的.tex文件,下面将删除整个标签,您可以自由地对标签进行硬编码。

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

Then your .rmd should look like this: 那你的.rmd应该是这样的:

---
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. 简化:正如评论中所建议的那样,我们可以在.Rmd文件中实现这一点,如下所示。

---
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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM