使用绘图和可更新(动态)字幕(图编号)生成 R Markdown Word.docx

Generating R Markdown Word.docx with Plots and Updatable (Dynamic) Captions (Figure Numbers)

我目前正在使用 Markdown 生成一个 Word.docx,其中包含使用 fig.cap

的情节和字幕
```{r, fig.width = 7.0, fig.height = 5.0, dpi = 400, echo=FALSE, results = FALSE, message = FALSE, warning = FALSE, fig.cap = "Figure 1: Plot Description", fig.align = "center"}

这确实为 Word 文档中的图表创建了标题,但是,Word 无法将文本识别为动态标题。有没有一种方法可以创建动态标题,以便在 Word 中时可以自动对图形重新编号,并且可以轻松创建 Table 的图形?

此解决方案有点笨拙,但确实会在 Word 中生成动态标题。 (我是 R 和 Markdown 的新手,所以可能有更好的方法来达到预期的结果)。

    library(officer)
    library(officedown)

sfig_num <- run_autonum(seq_id = "Figure", pre_label = "Figure 1", bkm="1")
    
block_caption("Caption Text Here", style = "caption", autonum = sfig_num)