问题描述
我想在用R Markdown创建的HTML文档中显示对图片的很好的交叉引用.但是,即使我遵循关于交叉引用的书本部分,我也无法获取要在最终HTML输出中显示的参考.如果有帮助,我正在R Studio中工作. .md文件:
I would like to show a nice cross-reference to a picture in the HTML document I'm creating with R Markdown. However, even if I followed the bookdown section on cross-references, I cannot get the reference to show in the final HTML output. I'm working in R Studio, if that helps. .Rmd file:
---
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).
我得到的输出是
因此标题正确呈现,但未创建交叉引用.我该如何解决?
So the caption is rendering correctly, but the cross-reference is not being created. How do I fix that?
推荐答案
我不确定.但是,您使用的是bookdown
吗?如果您遵循 https://bookdown.org/yihui/bookdown/get-started.html ,并按照 https://github.com/yihui/bookdown-minimal的方式使用bookdown项目.然后,您应该得到想要的结果.
I'm not sure. But are you using bookdown
? If you follow https://bookdown.org/yihui/bookdown/get-started.html, and use bookdown project as in https://github.com/yihui/bookdown-minimal. Then you should get the result you want.
例如,我使用 https://github.com/yihui/bookdown-minimal,然后将index.Rmd
修改为类似的格式,交叉引用就会正确显示.
For example, I use https://github.com/yihui/bookdown-minimal and modify the index.Rmd
to something like this, and the cross reference shows correctly.
--- title: "A Book" author: "Frida Gomam" site: bookdown::bookdown_site documentclass: book output: bookdown::gitbook: default bookdown::pdf_book: default ---
--- 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")
{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文档.
Update: Modify the output field to bookdown::html_document2
seems to generate the html document similar to rmarkdown::html_document
.
这篇关于在带有HTML输出的R Markdown中对图的交叉引用不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!