我最近开始为块标签添加前缀以帮助我识别预期的输出;即,情节的“情节”,表格的“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:同样的问题适用于 knitr::kable 字幕。
```{r tblcars}
kable(cars, caption = "This table caption works.")
```
```{r tbl_cars}
kable(cars, caption = "This table caption does not work.")
```