我想展示一个对我用R Markdown创建的HTML文档中图片的很好的交叉引用。但是,即使我遵循了the bookdown section on cross-references,我也无法获得要在最终的HTML输出中显示的引用。我在R工作室工作,如果有帮助的话。.Rmd文件:
---
title: "ppp"
author: "ppp"
date: "July 4, 2017"
output:
html_document:
fig_caption: yes
---
```{r setup, include=FALSE}
库(Knitr)
opts_chunk$set(echo =假)
```{r foo, fig.cap="$f_{p}$ as a function of $g$ for various values of $r=\\frac{\\rho_{w}}{\\rho_{a}}$"}
所有默认值
include_graphics("download.jpg")
A cross-reference to figure \@ref(fig:foo).
我得到的输出是
因此,标题呈现正确,但没有创建交叉引用。我该怎么解决这个问题呢?
发布于 2017-07-10 18:36:32
我没有把握。但是你在使用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文档。
https://stackoverflow.com/questions/45018180
复制相似问题