首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在bookdown中增加对照辅助数字/knitr/Rmarkdown

如何在bookdown中增加对照辅助数字/knitr/Rmarkdown
EN

Stack Overflow用户
提问于 2019-09-02 16:34:21
回答 1查看 291关注 0票数 6

图形的交叉引用非常有用,这要归功于谢一辉提供的非常有用的软件包bookdown。用户可以像本question中描述的那样引用图形

然而,当我为R中的科学论文撰写出版物时,我必须分开几组数字。第一组是进入出版物的数字,第二组是补充数字。

我想要一个单独的柜台来处理补充数字。目前在bookdown包中有没有办法做到这一点?

所以基本上我喜欢

代码语言:javascript
复制
\@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

最小工作示例:

代码语言:javascript
复制
---
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)

代码语言:javascript
复制
what would evaluate to Fig. S1. 


# Figures


```{r fig1main, fig.cap="First Main Figure"}

图(1)

代码语言:javascript
复制
```{r fig2main, fig.cap="Second Main Figure"}

图(1)

代码语言:javascript
复制
# Supplementary data

```{r fig1supp, fig.cap="This is a supplementary figure and it should be called Fig. S1 and not Fig 3."}

图(1)

代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

发布于 2021-10-21 20:17:17

这是一个迟来的答案,基于这个Restart Figure Numbering for Appendix / Supplementary Material in bookdown

代码语言:javascript
复制
---
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

}

代码语言:javascript
复制
# Chapter 1: Red section
  
```{r fig.id="red-plot1"}

new_chapter()

条形图(1:8,col1= "red4")

Block_caption(“一些红色条”,

代码语言:javascript
复制
          style = "Figure",
代码语言:javascript
复制
          autonum = run_autonum(seq_id = 'fig', 
代码语言:javascript
复制
                                start_at = 1, ##restart
代码语言:javascript
复制
                                bkm = 'red-plot1',
代码语言:javascript
复制
                                pre_label = paste0("Figure ", chapter_count, ".")))
代码语言:javascript
复制
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(“一些蓝条”,

代码语言:javascript
复制
          style = "Figure",
代码语言:javascript
复制
          autonum = run_autonum(seq_id = 'fig', 
代码语言:javascript
复制
                                start_at = 1, ##restart
代码语言:javascript
复制
                                bkm = 'blue-plot1',
代码语言:javascript
复制
                                pre_label = paste0("Figure ", chapter_count, ".")))
代码语言:javascript
复制
Figure `r chapter_count`.\@ref(fig:blue-plot1) shows some blue bars.

```{r fig.id="blue-plot2"}

条形图(8:1,col1= "dodgerblue3")

Block_caption(“更多蓝条”,

代码语言:javascript
复制
          style = "Figure",
代码语言:javascript
复制
          autonum = run_autonum(seq_id = 'fig', 
代码语言:javascript
复制
                                bkm = 'blue-plot2',
代码语言:javascript
复制
                                pre_label = paste0("Figure ", chapter_count, ".")))
代码语言:javascript
复制
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(“一些补充栏”,

代码语言:javascript
复制
          style = "Figure",
代码语言:javascript
复制
          autonum = run_autonum(seq_id = 'fig', 
代码语言:javascript
复制
                                start_at = 1, ##restart count
代码语言:javascript
复制
                                bkm = 'supp-plot1',
代码语言:javascript
复制
                                pre_label = "Figure S"))
代码语言:javascript
复制
Figure S\@ref(fig:supp-plot1) shows some supplementary bars
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57753758

复制
相关文章

相似问题

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