Reputation: 729
I have a document where I define a figure label once inside fig.caption
option in a chunk, and then reference it in the text using \ref{}
. For instance,
```{r dataCorrA, results="hold", echo = FALSE, fig.pos = "ht", fig.width=5, fig.height=5, fig.cap="\\label{fig:dataCorr} Some caption."}
data("airquality", package = "datasets")
GGally::ggcorr(airquality)
blah blah blah ... figure \ref{fig:dataCorr}
But upon knitting, I get
LaTeX Warning: Label `fig:dataCorr' multiply defined.
How can I get rid of the warning?
Upvotes: 2
Views: 956
Reputation: 729
This label is incorrect. Labels are defined with two colons ::
.
Eg. In knitr, the label option must have two colons, not one. Change the \\label
and the \ref
in text that follows.
```{r dataCorrA, results="hold", echo = FALSE, fig.pos = "ht", fig.width=5, fig.height=5, fig.cap="\\label{fig::dataCorr} Some caption."}
data("airquality", package = "datasets")
GGally::ggcorr(airquality)
blah blah blah ... figure \ref{fig::dataCorr}
Upvotes: 3