Ale*_*lex 7 latex r-markdown bookdown
某些类型的文件,例如期刊文章,通常有一个补充部分,其中数字的编号与主体不同.
例如,在主体中,您可能有图1-5.但是,对于补充部分,编号重新开始,如图S1,S2,S3等.
Bookdown允许交叉引用(\@ref(fig:label)但我不知道如何在单独的部分重新开始编号.有没有一个好方法可以做到这一点?
您可以在文件的YAML标头中定义新的LaTeX函数,.rmd如下所示:
\newcommand{\beginsupplement}{
\setcounter{table}{0}
\renewcommand{\thetable}{S\arabic{table}}
\setcounter{figure}{0}
\renewcommand{\thefigure}{S\arabic{figure}}
}
Run Code Online (Sandbox Code Playgroud)
然后\beginsupplement在准备开始用S1,S2 ...等标记图形和表格时键入内容。如果仅导出为PDF,则此解决方案可以很好地工作,因为它使用LaTeX命令格式化输出。因此,它不适用于HTML或Word输出。
---
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")
```
Run Code Online (Sandbox Code Playgroud)