下面的MWE应该通过引用\@ref(fig:chunk-label)正确地显示图形的数量,但是函数没有找到引用。是否有任何选项,我必须添加到块头,以实现正确的引用?
MWE:
---
title: "Untitled"
author: "dsf"
date: "18 1 2022"
output:
bookdown::pdf_document2:
keep_tex: yes
fig_caption: true
number_sections: true
toc: true
lot: true
lof: true
graphics: true
---
```{r decision-tree, fig.cap="Decision Tree Example for the strava irmi dataset", echo= FALSE, message = FALSE}图书馆(Rpart)
图书馆(拨浪鼓)
图书馆(Tidyverse)
附加(汽车)
火车&mtcar
列车<-列车%>%
变异( .cols = everything(),~scale(.x))
创建决策树模型
树<- rpart(mpg~.,data=train,cp=.05)
用rpart.plot可视化决策树
fancyRpartPlot(树,yesno=2,split.col=“黑”,nn.col=“黑”,
caption="Decision Tree Example for the irmi dataset",palette="Set3",branch.col="black") Figure \@ref(fig:decision-tree) shows an example of an decision tree for the irmi dataset. 编辑:感谢斯特凡。我密切关注knitr/rmarkdown/Latex: How to cross-reference figures and tables?并更新了MWE。可悲的是,解决方案并没有解决问题!
发布于 2022-01-18 19:21:38
这个问题相当微妙。要使您的引用工作,您必须在代码块和下面的文本之后添加一个中断行:
---
title: "Untitled"
author: "dsf"
date: "18 1 2022"
output:
bookdown::pdf_document2:
keep_tex: yes
fig_caption: true
number_sections: true
toc: true
lot: true
lof: true
graphics: true
---
```{r decision-tree, fig.cap="Decision Tree Example for the strava irmi dataset", echo= FALSE, message = FALSE}图书馆(Rpart)
图书馆(拨浪鼓)
图书馆(Tidyverse)
附加(汽车)
火车&mtcar
列车<-列车%>%
变异( .cols = everything(),~scale(.x))
创建决策树模型
树<- rpart(mpg~.,data=train,cp=.05)
用rpart.plot可视化决策树
fancyRpartPlot(树,yesno=2,split.col=“黑”,nn.col=“黑”,
caption="Decision Tree Example for the irmi dataset",palette="Set3",branch.col="black")Figure \@ref(fig:decision-tree) shows an example of an decision tree for the irmi dataset.

https://stackoverflow.com/questions/70760568
复制相似问题