【问题标题】:Rmarkdown: Modify Figure X label to Figure SX in pdf or word outputRmarkdown:在pdf或word输出中修改Figure X标签为Figure SX
【发布时间】:2021-03-25 14:58:56
【问题描述】:

我正在尝试使用 Rmarkdown 来自动标记 Figure 的标题,但我希望它不是 Figure 1,而是 Figure S1,即只是在那里添加 SAn example herehere 表明使用 pdf 输出是不可能的。好的,我对 .doc 文件很好,但我的图形标题仍然没有打印出来?我想知道有什么问题吗?

R 降价的最小示例:

    ---
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 来做。感谢您提出如何解决此问题的建议!

【问题讨论】:

  • 我编辑了答案以删除S 和数字之间的空格。所以,现在我们有 Figure S1 而不是 Figure S 1

标签: latex r-markdown knitr


【解决方案1】:

你可以在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 不是必需的;我使用它只是为了在同一页面中获取两个图并截取屏幕截图)

【讨论】:

  • 非常感谢@canovajsm!好的,简单的解决方案。我已经为此苦苦挣扎了好几天!拯救了我的一天:)
猜你喜欢
  • 2021-11-29
  • 1970-01-01
  • 1970-01-01
  • 2017-12-15
  • 1970-01-01
  • 2019-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多