使用带有PDF输出的R markdown,我想将一个图形引用到另一个图形标题中。我还想在标题中引用BibTex参考。有任何想法吗?这是代码示例:
---
title: "Untitled"
author: "me"
date: "today"
output:
pdf_document:
latex_engine: lualatex
number_sections: no
linestretch: 1.5
bibliography: input/Library.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure 1. I would also like a BibTex citation"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
答案 0 :(得分:1)
根据我的经验,当使用bookdown::pdf_document2
或bookdown::html_document2
时,交叉引用会更好。请注意,命名生成图形的块是有意义的,因为该名称用于引用的标签中:
---
title: "Untitled"
author: "me"
date: "today"
output:
bookdown::pdf_document2:
latex_engine: lualatex
number_sections: no
bookdown::html_document2:
default
linestretch: 1.5
bibliography: packages.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
knitr::write_bib(c(.packages()), 'packages.bib')
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r stuff, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure \\@ref(fig:stuff). I would also like a BibTex citation [@R-base]"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
对于BibTeX参考,我使用的是自动创建的参考,但是对您的情况的适应性应该是显而易见的。