在bookdown中重新启动附录/补充材料的图表编号

13

我正在为一份需要补充材料的期刊写文章。我希望使用一个独特的标签,比如SuppMat:,而不是默认的fig:来将图表发送到这个部分。如果不行,我可以使用默认的fig标签,但我需要在补充材料部分重新开始编号。

我知道有一个使用LaTeX的答案(在这里找到),但我必须在导出到docx时完成。下面是使用officedown的可重现示例。

---
output: 
  officedown::rdocx_document
---

```{r setup, include=FALSE}
pacman::p_load(knitr, officedown, officer)
knitr::opts_chunk$set(echo = FALSE,
                      eval = TRUE,
                      fig.cap = TRUE)
```

# Main Text

Please see Supplementary Figure \@ref(fig:appendix-fig1) and Figure \@ref(fig:main-fig1). 


```{r fig.id="main-fig1", fig.cap="This should be labelled **Figure 1**"}
barplot(1:5, col=1:5)
```

```{r tab.id="main-tab1", tab.cap="Main Text Table 1"}
head(mtcars)
```
\newpage

# Supplementary Materials {#SuppMat}

```{r fig.id="appendix-fig1", fig.cap="This figure should be labelled **Supplementary Figure 1**"}
barplot(1:5, col=1:5)
```

```{r tab.id="appendix-tab1", tab.cap="Should be labelled **Supplementary Table 1**"}
head(mtcars)
```
2个回答

6

在搜索多个论坛和花费数小时之后,我能够使用 officedown 包找到一个解决方案。希望这能帮到其他人。有关详细信息,请查看 run_autonum 函数。

---
output: officedown::rdocx_document
---

```{r setup, include=FALSE}
pacman::p_load(officedown, officer, knitr)
knitr::opts_chunk$set(echo = FALSE, fig.cap = TRUE)


ft_base <- fp_text(font.family = "Cambria", font.size = 12, bold = TRUE)
ft1 <- update(ft_base, shading.color='#EFEFEF', color = "red")
ft2 <- update(ft_base, color = "#C32900")

srcfile <- file.path( R.home("doc"), "html", "logo.jpg" )
extimg <- external_img(src = srcfile, height = 1.06/5, width = 1.39/5)
```



## References

This is a reference to an supplementary image caption whose number is Supplementary Figure \@ref(fig:faithfuld-plot) and \@ref(fig:supp-bar).

Testing another figure with a barplot in Figure \@ref(fig:plotbar)

```{r fig.id="plotbar", fig.cap = "Main Figure"}
barplot(1:8, col=1:2)
```

## Supplementary Material

```{r fig.id="faithfuld-plot"}
knitr::include_graphics("images/MyImage.png") # Use your own figure here (I needed to test with knitr for my workflow)

block_caption("First Appendix Figure",
              style = "Figure",
              autonum = run_autonum(seq_id = 'fig', 
                                    bkm = 'faithfuld-plot',
                                    pre_label = "Supplemental Figure ",
                                    start_at=1))
```

```{r fig.id="supp-bar"}
barplot(1:8, col=1:2)

block_caption("Second Appendix Figure",
              style = "Figure",
              autonum = run_autonum(seq_id = 'fig', 
                                    bkm = 'supp-bar',
                                    pre_label = "Supplemental Figure ",
                                    start_at= NULL))
```

1

在参考了@Patrick的答案之后,我找到了另一种方法。


```{r fig.id="faithfuld-plot", fig.cap.pre="Supplementary Figure",fig.autonum.start_at=1,fig.lp="supp-fig"}
knitr::include_graphics("images/MyImage.png") 

```
blah blah blah

```{r fig.id="faithfuld-plot2", fig.cap.pre="Supplementary Figure",fig.lp="supp-fig"}
knitr::include_graphics("images/MyImage2.png")

```

这应该使用“补充图”标签前缀,并且编号应从1开始。为了继续编号,请确保指定一个替代的.lp

fig.lptab.lp兼容。tabfig是可互换的


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接