【问题标题】:cite figure in other figure caption in markdown to pdf在降价到pdf的其他图形标题中引用图形
【发布时间】:2018-11-23 01:00:00
【问题描述】:

使用带有 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()
```

【问题讨论】:

    标签: r latex r-markdown pandoc


    【解决方案1】:

    根据我的经验,当使用bookdown::pdf_document2bookdown::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 参考,我使用的是自动创建的,但对您的情况的适应应该是显而易见的。

    【讨论】:

    • 这并不能概括为html_output。有一个解决方案会很好。
    • @FrankHarrell 对于 HTML 输出,您可以使用 bookdown::html_document2。查看更新的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    • 2020-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    相关资源
    最近更新 更多