1

我最近开始为块标签添加前缀以帮助我识别预期的输出;即,情节的“情节”,表格的“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.")
```
4

1 回答 1

1

来自blogdown的附录 A

[...] 并且您需要阅读bookdown 书(Xie 2016)的第 2 章,以了解有关这些 [R Markdown] 功能的更多信息。

来自bookdown book的第 2.4 节

如果要交叉引用从代码块生成的图形或表格,请确保块标签仅包含字母数字字符 ( a-z, A-Z, 0-9)、斜线 ( /) 或破折号 ( -)。

如果要编号或交叉引用数字,则不支持下划线。

于 2017-10-15T03:59:09.533 回答