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

查看:11
本文介绍了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.

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 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:


ewcommand{eginsupplement}{
  setcounter{table}{0}  
  
enewcommand{	hetable}{Sarabic{table}} 
  setcounter{figure}{0} 
  
enewcommand{	hefigure}{Sarabic{figure}}
}

Then type eginsupplement 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*
- '*	extit{email@example.com} vspace{5mm}'
output: 
  bookdown::pdf_document2
fontsize: 12pt
header-includes: 
  usepackage{float} floatplacement{figure}{H} 
  
ewcommand{eginsupplement}{setcounter{table}{0}  
enewcommand{	hetable}{Sarabic{table}} setcounter{figure}{0} 
enewcommand{	hefigure}{Sarabic{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()
```


ewpage
# Supplementary material {-}

eginsupplement


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天全站免登陆