跨引用 R Markdown 中的子图。

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

Cross Reference Subfigures in R Markdown

问题

  1. 我在R Markdown中有一个包含子图的图。如何在文本中交叉引用这些图,例如`Figure 1a``Figure 1b`等?
  2. ~~~
  3. ```{r figgy, fig.cap='Caption', echo = FALSE, fig.ncol = 2, out.width = "50%", fig.align = "center", fig.subcap=c('(a)', '(b)', '(c)')}
  4. plot(1:10)
  5. plot(cars, pch = 19)
  6. boxplot(Sepal.Width ~ Species, data = iris)
  1. 来自[R Markdown Cookbook][1]的代码。我正在使用`bookdown::tufte_handout2`
  2. [1]: https://bookdown.org/yihui/rmarkdown-cookbook/latex-subfigure.html
  3. ```
  4. <details>
  5. <summary>英文:</summary>
  6. I have a figure with subfigures in R Markdown. How do I cross-reference these in the text as `Figure 1a`, `Figure 1b` etc?
  1. plot(1:10)
  2. plot(cars, pch = 19)
  3. boxplot(Sepal.Width ~ Species, data = iris)
  1. Code from [R Markdown Cookbook][1]. I&#39;m using `bookdown::tufte_handout2`
  2. [1]: https://bookdown.org/yihui/rmarkdown-cookbook/latex-subfigure.html
  3. </details>
  4. # 答案1
  5. **得分**: 3
  6. 使用`\subref*`命令引用子图。通常,交叉引用的语法应为`\subref*{<code-chunk-label>:<plot-serial-no>}`。我已经使用了`subrefformat=simple`,使得引用样式看起来像`1a`而不是`1(a)`
  7. - \subref*{fig:figgy-1} 是一个散点图
  8. - \subref*{fig:figgy-2} 是另一个散点图
  9. - \subref*{fig:figgy-3} 是一个箱线图
  10. <details>
  11. <summary>英文:</summary>
  12. 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}

  1. #| label: figgy
  2. #| fig.cap: &quot;Caption&quot;
  3. #| echo: false
  4. #| fig.ncol: 2
  5. #| out.width: &quot;50%&quot;
  6. #| fig.align: &quot;center&quot;
  7. #| fig.subcap: !expr c(&quot;A boring scatterplot&quot;, &quot;Another scatterplot&quot;, &quot;A boxplot&quot;)
  8. #| fig.height: 3
  9. plot(1:10)
  10. plot(cars, pch = 19)
  11. 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
  1. &lt;hr&gt;
  2. [![cross referencing to subfigures in bookdown::tufte_handout2][1]][1]
  3. [1]: https://i.stack.imgur.com/3E826.png
  4. </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:

确定