将R Markdown转为Word时自定义图标题为Supplementary Figure
解决方法
要在bookdown::word_document2输出的docx中把图标题前缀从默认的"Figure"改为"Supplementary Figure",同时保留markdown格式的caption支持,可按以下步骤操作:
- 在文档开头添加全局设置代码块,配置bookdown的标题编号格式:
```{r setup, include=FALSE} knitr::opts_knit$set(bookdown.label.format = list(fig = "Supplementary Figure %s:"))
2. 保留原有的文档结构和图块代码即可,无需修改其他配置。 完整示例代码如下:
output:
bookdown::word_document2:
reference_docx: "StyleTemplate.docx"
fig_caption: true
knitr::opts_knit$set(bookdown.label.format = list(fig = "Supplementary Figure %s:"))
variables <- 2 plot(cars) # figure content
(ref:caption) Caption to the figure might contain markdown $^1$ or r variables
### 说明 - 此方法通过bookdown内置的标题编号配置实现前缀替换,不需要修改docx模板的文本内容,仅需在Rmd中添加设置代码。 - 保留了`bookdown::word_document2`对markdown格式caption的支持,满足标题中包含斜体、上标、代码等格式的需求。 内容的提问来源于stack exchange,提问作者Martin Smith
相关产品推荐
相关产品推荐

