英文:
Cross Reference Subfigures in R Markdown
问题
我在R Markdown中有一个包含子图的图。如何在文本中交叉引用这些图,例如`Figure 1a`,`Figure 1b`等?
~~~
```{r figgy, fig.cap='Caption', echo = FALSE, fig.ncol = 2, out.width = "50%", fig.align = "center", fig.subcap=c('(a)', '(b)', '(c)')}
plot(1:10)
plot(cars, pch = 19)
boxplot(Sepal.Width ~ Species, data = iris)
来自[R Markdown Cookbook][1]的代码。我正在使用`bookdown::tufte_handout2`
[1]: https://bookdown.org/yihui/rmarkdown-cookbook/latex-subfigure.html
```
<details>
<summary>英文:</summary>
I have a figure with subfigures in R Markdown. How do I cross-reference these in the text as `Figure 1a`, `Figure 1b` etc?
plot(1:10)
plot(cars, pch = 19)
boxplot(Sepal.Width ~ Species, data = iris)
Code from [R Markdown Cookbook][1]. I'm using `bookdown::tufte_handout2`
[1]: https://bookdown.org/yihui/rmarkdown-cookbook/latex-subfigure.html
</details>
# 答案1
**得分**: 3
使用`\subref*`命令引用子图。通常,交叉引用的语法应为`\subref*{<code-chunk-label>:<plot-serial-no>}`。我已经使用了`subrefformat=simple`,使得引用样式看起来像`1a`而不是`1(a)`。
- 图 \subref*{fig:figgy-1} 是一个散点图
- 图 \subref*{fig:figgy-2} 是另一个散点图
- 图 \subref*{fig:figgy-3} 是一个箱线图
<details>
<summary>英文:</summary>
Use the `\subref*` command to refer to the subfigures. Usually, the cross-referencing syntax would be `\subref*{<code-chunk-label>:<plot-serial-no>}`. And I have used `subrefformat=simple` so that the reference style looks like `1a` instead of `1(a)`.
title: Cross-referencing subfigures
output:
bookdown::tufte_handout2:
header-includes:
- \usepackage[subrefformat=simple]{subfig}
#| label: figgy
#| fig.cap: "Caption"
#| echo: false
#| fig.ncol: 2
#| out.width: "50%"
#| fig.align: "center"
#| fig.subcap: !expr c("A boring scatterplot", "Another scatterplot", "A boxplot")
#| fig.height: 3
plot(1:10)
plot(cars, pch = 19)
boxplot(Sepal.Width ~ Species, data = iris)
- Figure \subref*{fig:figgy-1} is a scatterplot
- Figure \subref*{fig:figgy-2} is another scatterplot
- Figure \subref*{fig:figgy-3} is a boxplot
<hr>
[![cross referencing to subfigures in bookdown::tufte_handout2][1]][1]
[1]: https://i.stack.imgur.com/3E826.png
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论