如何在 RMarkdown 中删除自定义图形标题和自动生成的数字之间的空格?

问题描述 投票:0回答:1

我正在尝试更改 RMarkdown 文件中的图形标题,以具有“图 S1”、“图 S2”等的重复样式。为此,我尝试在 RMarkdown 中运行以下基本代码:

---
title: "Test"
author: "Shawn Hemelstrand"
date: "`r Sys.Date()`"
output: 
  pdf_document
header-includes:
- \usepackage{caption}
- \captionsetup[figure]{name=Figure S}
---

```{r plot,echo=FALSE, fig.cap="Some informative description."}
plot(iris$Petal.Width,
     iris$Petal.Length)
```

但是,您可以从下面的输出中看到,它在“S”和图形编号之间创建了不必要的空格。

我想要这里的“S1”而不是“S 1”。我该如何解决这个问题?

r pdf latex r-markdown figure
1个回答
0
投票

您可以重新定义图形的计数器,例如

---
title: "Test"
author: "Shawn Hemelstrand"
date: "`r Sys.Date()`"
format:
  pdf:
    fig-labels: 
header-includes:
- \usepackage{caption}
- \captionsetup[figure]{name=Figure}
- \setcounter{figure}{0}
- \renewcommand{\thefigure}{S\arabic{figure}}
---

```{r plot,echo=FALSE, fig.cap="Some informative description."}
plot(iris$Petal.Width,
     iris$Petal.Length)
```

结果

© www.soinside.com 2019 - 2024. All rights reserved.