【问题标题】:Officer for Rmarkdown: Cross-referencing block_captions not numbering correctlyRmarkdown 官员:交叉引用 block_captions 编号不正确
【发布时间】:2021-10-05 07:39:58
【问题描述】:

我正在使用officer 包中的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", 
                           pre_label = "Figure S", 
                           bkm="f-s2")
    
    block_caption("A figure caption.", 
                  style = "Image Caption", 
                  autonum = sfig_num)
    ```

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

【问题讨论】:

    标签: r-markdown officer officedown


    【解决方案1】:

    我发现如果您使用 r run_reference(bkm-id) 而不是 bookdown 样式的 \@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", 
                               pre_label = "Figure S", 
                               bkm="fs2")
        
        block_caption("A figure caption.", 
                      style = "Image Caption", 
                      autonum = sfig_num)
        ```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      • 2018-10-14
      • 1970-01-01
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      • 2023-02-01
      相关资源
      最近更新 更多