I'm having trouble with figure captions in html documents generated using R Markdown. If I don't specify the fig.retina option, or if I set it to 1, the output document has a figure caption. If I set it to a value that isn't 1, however, the future caption is missing but the text for it is present as the alt text for the figure. How can I keep the figure captions?
我在使用R Markdown生成的html文档中遇到数字标题时遇到问题。如果我没有指定fig.retina选项,或者我将其设置为1,则输出文档具有数字标题。但是,如果我将其设置为不是1的值,则会丢失未来的标题,但其文本将作为图形的替代文本显示。如何保留数字标题?
An example:
一个例子:
---
title: "Example"
output:
html_document:
fig_caption: yes
fig_retina: 2
---
Text text text
```{r fig.cap="Figure 1. Some random numbers"}
plot(rnorm(25),runif(25))
```
Renders to give a document with no figure caption, but if I change the value for fig.retina to 1 I get a figure caption. The same thing happens if I set fig.retina in the chunk rather than globally.
渲染给出一个没有图形标题的文档,但如果我将fig.retina的值更改为1,我会得到一个数字标题。如果我在块中设置fig.retina而不是全局,则会发生同样的事情。
1 个解决方案
#1
1
Here is the relevant documentation
这是相关文档
#' @param fig_retina Scaling to perform for retina displays (defaults to 2 when
#' \code{fig_caption} is \code{FALSE}, which currently works for all widely
#' used retina displays). Set to \code{NULL} to prevent retina scaling. Note
#' that this will always be \code{NULL} when \code{keep_md} is specified (this
#' is because \code{fig_retina} relies on outputting HTML directly into the
#' markdown document).
#' @param fig_caption \code{TRUE} to render figures with captions
So if you don't specify the default will be 2. I did find that if I changed your code to
因此,如果你没有指定默认值将是2.我确实发现如果我将代码更改为
---
title: "Example"
output:
html_document:
fig_caption: yes
---
Text text text
```{r fig.cap="Figure 1. Some random numbers"}
plot(rnorm(25),runif(25))
```
It showed the caption.
它显示了标题。
update
更新
After looking around a bit I found this
环顾四周后我发现了这个
Note the chunk option fig.retina=1: without it, rmarkdown::render() will generate plots for Retina displays, which means the plots are written in raw
<img>
tags instead of![]()
, and Pandoc will not be able to generate figure captions in that case.注意块选项fig.retina = 1:没有它,rmarkdown :: render()将生成Retina显示的图,这意味着图是用原始标签而不是![]()编写的,并且Pandoc不会在这种情况下能够生成数字标题。
So probably you need to just use normal markdown for adding html for the caption.
因此,您可能需要使用正常的降价来为标题添加html。
#1
1
Here is the relevant documentation
这是相关文档
#' @param fig_retina Scaling to perform for retina displays (defaults to 2 when
#' \code{fig_caption} is \code{FALSE}, which currently works for all widely
#' used retina displays). Set to \code{NULL} to prevent retina scaling. Note
#' that this will always be \code{NULL} when \code{keep_md} is specified (this
#' is because \code{fig_retina} relies on outputting HTML directly into the
#' markdown document).
#' @param fig_caption \code{TRUE} to render figures with captions
So if you don't specify the default will be 2. I did find that if I changed your code to
因此,如果你没有指定默认值将是2.我确实发现如果我将代码更改为
---
title: "Example"
output:
html_document:
fig_caption: yes
---
Text text text
```{r fig.cap="Figure 1. Some random numbers"}
plot(rnorm(25),runif(25))
```
It showed the caption.
它显示了标题。
update
更新
After looking around a bit I found this
环顾四周后我发现了这个
Note the chunk option fig.retina=1: without it, rmarkdown::render() will generate plots for Retina displays, which means the plots are written in raw
<img>
tags instead of![]()
, and Pandoc will not be able to generate figure captions in that case.注意块选项fig.retina = 1:没有它,rmarkdown :: render()将生成Retina显示的图,这意味着图是用原始标签而不是![]()编写的,并且Pandoc不会在这种情况下能够生成数字标题。
So probably you need to just use normal markdown for adding html for the caption.
因此,您可能需要使用正常的降价来为标题添加html。