【问题标题】:Reference one of several figures in r code chunk of a Rnw file在 Rnw 文件的 r 代码块中引用几个图形之一
【发布时间】:2019-04-02 18:16:21
【问题描述】:

使用 rnw 文件创建参数化报告。我正在尝试从其中包含多个数字的代码块中引用特定数字(由通过数字列表的循环生成)。我知道如果有一个单一的数字,我可以使用 \ref{fig:foo} 从块标签中引用它,正如 Yihui 在 https://bookdown.org/yihui/bookdown/figures.html 中提到的那样。但我似乎无法引用该块中的具体数字。我尝试引用独特的图形标题或整体块,但两者都给了我??。有没有办法做到这一点?

我搜索了这个Dynamic LaTeX references in R comment with knitr 及其相关的问题,但未能成功。

同样在 Figures captions and labels in knitr 中,这些图被组合成一个大图,绕过了这个问题。

MVWE:

\documentclass{article}

\usepackage{float}
\usepackage{hyperref}
\usepackage{caption} % Needs to be after hyperref. jumps you to top of figure not to label.

\begin{document}



<<figures, fig.cap=c('fig1','fig2')>>=
library(knitr)
library(markdown)
library(rmarkdown)
library(ggplot2)

figure1 <- ggplot(mtcars) + geom_point(aes(x=mpg,y=cyl))
figure2 <- ggplot(mtcars) + geom_point(aes(x=drat,y=wt))

plots <- list(figure1,figure2)

plots
@


as we can see in \ref{fig:figures}

\end{document}

【问题讨论】:

    标签: r knitr rnw


    【解决方案1】:

    只需在其上附加一个数字:

    as we can see in \ref{fig:figures1} and \ref{fig:figures2}
    

    要弄清楚这一点,您应该查看.tex 文件,其中包含

    \begin{figure}
    \includegraphics[width=\maxwidth]{figure/figures-1} \caption[fig1]{fig1}\label{fig:figures1}
    \end{figure}
    

    第一个,另一个类似的东西。 \label{fig:figures1} 部分是您的 \ref 需要引用的部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-07
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多