【问题标题】:cross-reference to figure in R Markdown with html output is not working使用 html 输出交叉引用 R Markdown 中的图形不起作用
【发布时间】:2017-07-10 17:23:39
【问题描述】:

我想在我使用 R Markdown 创建的 HTML 文档中显示对图片的很好的交叉引用。但是,即使我关注了the bookdown section on cross-references,我也无法在最终的 HTML 输出中显示该引用。我在 R Studio 工作,如果有帮助的话。 .Rmd 文件:

---
title: "ppp"
author: "ppp"
date: "July 4, 2017"
output: 
  html_document: 
    fig_caption: yes
---

```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = FALSE)
```


```{r foo, fig.cap="$f_{p}$ as a function of $g$ for various values of $r=\\frac{\\rho_{w}}{\\rho_{a}}$"}
# All defaults
include_graphics("download.jpg")
```

A cross-reference to figure \@ref(fig:foo).

我得到的输出是

所以标题渲染正确,但没有创建交叉引用。我该如何解决?

【问题讨论】:

    标签: html r r-markdown figure caption


    【解决方案1】:

    我不确定。但是您使用的是bookdown 吗?如果您关注https://bookdown.org/yihui/bookdown/get-started.html,并使用https://github.com/yihui/bookdown-minimal 中的bookdown 项目。那么你应该得到你想要的结果。

    例如,我使用https://github.com/yihui/bookdown-minimal 并将index.Rmd 修改为类似的内容,交叉引用显示正确。

    --- title: "A Book" author: "Frida Gomam" site: bookdown::bookdown_site documentclass: book output: bookdown::gitbook: default bookdown::pdf_book: default ---

    {r foo, fig.cap="$f_{p}$ as a function of $g$ for various values of $r=\\frac{\\rho_{w}}{\\rho_{a}}$", echo=FALSE} # All defaults knitr::include_graphics("download.png")

     A cross-reference to figure \@ref(fig:foo).
    

    更新:修改输出字段为bookdown::html_document2似乎生成了类似于rmarkdown::html_document的html文档。

    【讨论】:

    • 我不明白bookdownrmarkdown 是不同的包:感谢您的澄清。难道不能以普通的rmarkdown 获得交叉引用吗?如果不是,我可以接受您的回答,如果您修改它以便文件呈现为 HTML 文件,而不是呈现为 HTML 文件。
    • bookdown::html_document2 似乎与rmarkdown::html_document 相似。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多