跨引用 R Markdown 中的子图。

huangapple go评论57阅读模式
英文:

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&#39;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*{&lt;code-chunk-label&gt;:&lt;plot-serial-no&gt;}`. 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: &quot;Caption&quot;
#| echo: false
#| fig.ncol: 2
#| out.width: &quot;50%&quot;
#| fig.align: &quot;center&quot;
#| fig.subcap: !expr c(&quot;A boring scatterplot&quot;, &quot;Another scatterplot&quot;, &quot;A boxplot&quot;)
#| 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

&lt;hr&gt;

[![cross referencing to subfigures in bookdown::tufte_handout2][1]][1]


  [1]: https://i.stack.imgur.com/3E826.png

</details>



huangapple
  • 本文由 发表于 2023年4月17日 12:37:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031750.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定