我最近开始在区块标签前加前缀,以帮助我识别预期的输出;即,"绘图"表示绘图,"tbl"表示表格等。
今天早上,我试图在一个情节中添加一个fig.cap。标题将无法正确显示;它看起来像这样:
(#fig:plt_cars)此标题将无法正确显示。
我期待这个:
图1:此标题将正确显示。
经过反复研究,我发现在区块标签中添加"plot"或"plt"作为前缀会导致这种情况。
下面的示例演示了这一点。
---
title: Test Post
author: Tim Trice
date: '2017-10-14'
slug: test-post
categories: []
tags: []
---
```{r}
library(ggplot2)
```
```{r}
data(cars)
```
```{r cars, fig.cap = "This caption will display correctly."}
ggplot(cars, aes(x = speed, y = dist)) + geom_point()
```
```{r plt_cars, fig.cap = "This caption will not display correctly."}
ggplot(cars, aes(x = speed, y = dist)) + geom_point()
```
```{r plot_cars, fig.cap = "Nor will this caption display correctly."}
ggplot(cars, aes(x = speed, y = dist)) + geom_point()
```
在普通Rmd文档中,所有标题都会显示良好;但博客中没有。
我正在使用blogdown 0.1。
我已经在Debian和Windows上验证了这一点,但目前只有R 3.4.0。
有人能告诉我为什么不能使用这些前缀吗?
编辑:它不是前缀,而是使用分隔符"_"或"."。
这些例子不起作用:
```{r test_cars, fig.cap = "Nor will this caption display correctly."}
ggplot(cars, aes(x = speed, y = dist)) + geom_point()
```
```{r test.cars, fig.cap = "Nor will this caption display correctly."}
ggplot(cars, aes(x = speed, y = dist)) + geom_point()
```
```{r c_a_r_s, fig.cap = "Nor will this caption display correctly."}
ggplot(cars, aes(x = speed, y = dist)) + geom_point()
```
编辑2:同样的问题也适用于编织者::可行的标题。
```{r tblcars}
kable(cars, caption = "This table caption works.")
```
```{r tbl_cars}
kable(cars, caption = "This table caption does not work.")
```
来自blogdown书的附录A:
[…],您需要阅读bookdown书(谢2016)的第2章来了解更多关于[R Markdown]功能的信息。
来自书籍的第2.4节:
如果要交叉引用代码块生成的图形或表格,请确保块标签仅包含字母数字字符(
a-z
、A-Z
、0-9
)、斜线(/
)或短划线(-
)。
如果要对数字进行编号或交叉引用,则不支持下划线。