首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rmarkdown的官员:交叉引用block_captions编号不正确

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

Stack Overflow用户
提问于 2021-07-29 16:09:59
回答 1查看 89关注 0票数 0

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

下面是一个reprex Rmd文件:

代码语言:javascript
复制
    ---
    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", 
                           pre_label = "Figure S", 
                           bkm="f-s2")
    
    block_caption("A figure caption.", 
                  style = "Image Caption", 
                  autonum = sfig_num)
    ```

这是一个截图,正确的标题编号用蓝色圈出;错误的交叉引用编号用红色圈出。

EN

回答 1

Stack Overflow用户

发布于 2021-07-31 13:05:38

我想,如果你使用r run_reference(bkm-id)而不是bookdown风格的\@ref(bkm-id),那么编号就会起作用:

代码语言:javascript
复制
    ---
    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", 
                           pre_label = "Figure S", 
                           bkm="fs2")
    
    block_caption("A figure caption.", 
                  style = "Image Caption", 
                  autonum = sfig_num)
    ```

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68579449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档