图形的交叉引用非常有用,这要归功于谢一辉提供的非常有用的软件包bookdown。用户可以像本question中描述的那样引用图形
然而,当我为R中的科学论文撰写出版物时,我必须分开几组数字。第一组是进入出版物的数字,第二组是补充数字。
我想要一个单独的柜台来处理补充数字。目前在bookdown包中有没有办法做到这一点?
所以基本上我喜欢
\@ref(fig:figure1) # evaluates to Fig. 1
\@ref(fig:figure2) # evaluates to Fig. 2
\@ref(figS:supplementary-figure1) #evaluates to Fig. S1. PS。对我来说,最重要的输出是bookdown::word_document2
最小工作示例:
---
title: "MWD"
output: bookdown::word_document2
---
# Results
This text refers to Fig. \@ref(fig:fig1main).
We also want to refere here to Fig. \@ref(fig:fig2main).
In some cases we also need supplementary data. Please see Suppl. Fig. S\@ref(fig:fig1supp).
Please note that the 'S' before the reference should optimally NOT be there and ideally one should write:图3.\@ref(图:图1supp)
what would evaluate to Fig. S1.
# Figures
```{r fig1main, fig.cap="First Main Figure"}图(1)
```{r fig2main, fig.cap="Second Main Figure"}图(1)
# Supplementary data
```{r fig1supp, fig.cap="This is a supplementary figure and it should be called Fig. S1 and not Fig 3."}图(1)
发布于 2021-10-21 20:17:17
这是一个迟来的答案,基于这个Restart Figure Numbering for Appendix / Supplementary Material in bookdown。
---
output: officedown::rdocx_document
---
```{r setup, include=FALSE}Pacman::p_load(办公室、官员、针织)
knitr::opts_chunk$set(echo =假)
自定义函数,在每个新章节的开头重新开始编号。
您也可以手动执行此操作!
函数<- new_chapter (){
如果(!exists(“chapter_count”))chapter_count <<- 0
chapter_count <<- chapter_count +1
}
# Chapter 1: Red section
```{r fig.id="red-plot1"}new_chapter()
条形图(1:8,col1= "red4")
Block_caption(“一些红色条”,
style = "Figure", autonum = run_autonum(seq_id = 'fig', start_at = 1, ##restart bkm = 'red-plot1', pre_label = paste0("Figure ", chapter_count, ".")))Figure `r chapter_count`.\@ref(fig:red-plot1) shows some red bars.
# Chapter 2 : Blue section
```{r fig.id="blue-plot1"}new_chapter()
条形图(1:8,col1= "dodgerblue3")
Block_caption(“一些蓝条”,
style = "Figure", autonum = run_autonum(seq_id = 'fig', start_at = 1, ##restart bkm = 'blue-plot1', pre_label = paste0("Figure ", chapter_count, ".")))Figure `r chapter_count`.\@ref(fig:blue-plot1) shows some blue bars.
```{r fig.id="blue-plot2"}条形图(8:1,col1= "dodgerblue3")
Block_caption(“更多蓝条”,
style = "Figure", autonum = run_autonum(seq_id = 'fig', bkm = 'blue-plot2', pre_label = paste0("Figure ", chapter_count, ".")))Figure `r chapter_count`.\@ref(fig:blue-plot2) shows some more blue bars.
# Supplementary section
```{r fig.id="supp-plot1"}barplot(1:4,main =“补充栏”)
Block_caption(“一些补充栏”,
style = "Figure", autonum = run_autonum(seq_id = 'fig', start_at = 1, ##restart count bkm = 'supp-plot1', pre_label = "Figure S"))Figure S\@ref(fig:supp-plot1) shows some supplementary barshttps://stackoverflow.com/questions/57753758
复制相似问题