Rmarkdown:在pdf或word输出中将Figure X标签修改为Figure SX

Rmarkdown: Modify Figure X label to Figure SX in pdf or word output

我正在尝试使用 Rmarkdown 自动标记图的标题,但我希望它不是 Figure 1,而是 Figure S1,即只需在此处添加 SAn example here and 建议使用 pdf 输出这是不可能的。好的,我可以使用 .doc 文件,但我的图形标题仍然没有打印出来?我想知道有什么问题吗?

R markdown 的最小示例:

    ---
title: Supporting Information
subtitle: "Iron(I) etc"
author: "Some people here"
abstract: "Added the addresses here since there is no abstract in the SI"
output:
  word_document:
    fig_caption: yes
---

```{r, include=F}
library(captioner)

figS<- captioner(prefix = "Figure S", auto_space = TRUE, levels = 1, type = NULL,  infix = ".")

figS("Figure S1", "Single-crystal X-ray structure of some text (1)", display=FALSE)

```

```{r Xray, fig.cap=figS("This is my figure description"), echo=FALSE}
plot(cars)
```

这会正确打印出来 Figure S1。但是,现在我的真实人物描述不见了?

我想要的输出是pdf,如果不是,我可以用word。感谢您提出解决此问题的建议!

YAML部分header-includes:下可以使用一些LaTeX命令,如下:

---
title: "Untitled"
output: pdf_document
header-includes:
  - \renewcommand{\figurename}{Figure S}
  - \makeatletter
  - \def\fnum@figure{\figurename\thefigure}
  - \makeatother
---

```{r, fig.cap="This is my figure description", fig.height=3}
plot(pressure)
```

```{r, fig.cap="Another figure description", fig.height=3}
plot(iris$Sepal.Length, iris$Petal.Width)
```

(R 代码块中的参数 fig.height 不是必需的;我用它只是为了在同一页中获取两个图并截取屏幕截图)