Rmarkdown/Bookdown:补充部分的单独图形编号 [英] Rmarkdown/Bookdown: Separate figure numbering for Supplemental Section

查看:180
本文介绍了Rmarkdown/Bookdown:补充部分的单独图形编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些类型的文档(例如期刊文章)通常具有一个补充部分,其中附图编号与正文不同.

Certain kinds of documents, such as journal articles, often have a Supplemental Section, where the numbering of figures is different from the main body.

例如,在主体中,您可能会看到图1-5.但是,对于补充部分,编号重新开始,如图S1,S2,S3等.

For example, in the main body, you might have Fig 1-5. But then, for the Supplemental section, the numbering restarts as Fig S1, S2, S3, etc.

Bookdown允许交叉引用(\@ref(fig:label),但我不确定如何在单独的部分中重新编号.是否有很好的方法来做到这一点?

Bookdown allows cross-referencing (\@ref(fig:label) but I'm not sure how to restart the numbering in a separate section. Is there a good way to do this?

推荐答案

您可以定义一个新的

You can define a new LaTeX function in the YAML header of your .rmd file as follows:

\newcommand{\beginsupplement}{
  \setcounter{table}{0}  
  \renewcommand{\thetable}{S\arabic{table}} 
  \setcounter{figure}{0} 
  \renewcommand{\thefigure}{S\arabic{figure}}
}

然后当您准备开始使用S1,S2 ...等标记图形和表格时,键入\beginsupplement.如果仅导出为PDF,则此解决方案可以很好地工作,因为它使用LaTeX命令来格式化输出.因此,它不适用于HTML或Word输出.

Then type \beginsupplement when you're ready to start labelling the figures and tables with S1, S2... etc. This solution works fine if you export to PDF only, as it uses LaTeX commands to format the output. It therefore will not work for HTML or Word outputs.

---
title: "title"
author:
- My Namington*
- '*\textit{email@example.com} \vspace{5mm}'
output: 
  bookdown::pdf_document2
fontsize: 12pt
header-includes: 
  \usepackage{float} \floatplacement{figure}{H} 
  \newcommand{\beginsupplement}{\setcounter{table}{0}  \renewcommand{\thetable}{S\arabic{table}} \setcounter{figure}{0} \renewcommand{\thefigure}{S\arabic{figure}}}
---

```{r, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(ggplot2)
```


# Main text
Here is the main text of my paper, and a link to a normally-labelled Figure \@ref(fig:irisPlot).

```{r irisPlot, fig.cap="This is a figure caption."}

ggplot(iris, aes(Species, Sepal.Length, colour = Species)) + geom_jitter()
```

\newpage
# Supplementary material {-}

\beginsupplement


Here is the supplement, including a link to a figure prefixed with the letter S Figure \@ref(fig:irisPlot2).

```{r irisPlot2, echo=FALSE, fig.cap= "This is a supplementary figure caption."}
ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) + 
    geom_point() + 
    stat_smooth(method = "lm")
```

这篇关于Rmarkdown/Bookdown:补充部分的单独图形编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆