0

I'm using run_autonum and block_caption from the officer package to create figure captions for my supplemental figures and then cross-reference them (want to be a separate series than the non-supplemental figures so the numbering restarts). The numbering in the figure caption is working great (1, 2, ...). However, when cross-referencing, the number shows up as 0.

Here's a reprex Rmd file:

    ---
    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)
    ```

Here's a screenshot with correct caption numbering circled in blue; incorrect cross-reference numbering circled in red. enter image description here

Alton
  • 137
  • 6

1 Answers1

0

I figured out that the numbering works if you use r run_reference(bkm-id) instead of bookdown-style \@ref(bkm-id) it works:

    ---
    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)
    ```

screenshot of word output

Alton
  • 137
  • 6