Rmarkdown 官员:交叉引用 block_captions 编号不正确

问题描述

我正在使用官员包中的 run_autonum 和 block_caption 为我的补充数字创建图表标题,然后交叉引用它们(希望成为与非补充数字不同的系列,以便重新编号)。图标题中的编号效果很好(1、2、...)。但是,当交叉引用时,数字显示为 0。

这是一个 reprex Rmd 文件

    ---
    title: "Untitled"
    output: 
      officedown::rdocx_document
    ---

    Supplemental figure \@ref(f-s1). Supplemental figure \@ref(f-s2)
    
    ```{r,echo=FALSE}
    library(officer)
    
    sfig_num <- run_autonum(seq_id = "sfig",pre_label = "figure S",bkm="f-s1")
    
    block_caption("A figure caption.",style = "Image Caption",autonum = sfig_num)
    
    sfig_num <- run_autonum(seq_id = "sfig",bkm="f-s2")
    
    block_caption("A figure caption.",autonum = sfig_num)
    ```

这是一个屏幕截图,带有正确的标题编号,用蓝色圈起来;不正确的交叉引用编号以红色圈出。

enter image description here

解决方法

我发现如果您使用 r run_reference(bkm-id) 而不是 bookdown-style \@ref(bkm-id) 则编号有效:

    ---
    title: "Untitled"
    output: 
      officedown::rdocx_document
    ---
    
    ```{r echo=FALSE,warning=FALSE}
    library(officer)
    library(officedown)
    ```
    
    
    Supplemental figure `r run_reference("fs1")`. Supplemental figure `r run_reference("fs2")`
    
    
    ```{r,echo=FALSE,warning=FALSE}
    sfig_num <- run_autonum(seq_id = "sfig",pre_label = "Figure S",bkm="fs1")
    
    block_caption("A figure caption.",style = "Image Caption",autonum = sfig_num)
    
    sfig_num <- run_autonum(seq_id = "sfig",bkm="fs2")
    
    block_caption("A figure caption.",autonum = sfig_num)
    ```

screenshot of word output