【问题标题】:Prefixing chunk label with "plot" or "plt" modifies figure caption用“plot”或“plt”前缀块标签修改图形标题
【发布时间】:2017-10-14 16:36:53
【问题描述】:

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

【问题讨论】:

    标签: r blogdown


    【解决方案1】:

    来自Appendix A of the blogdown book

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

    来自Section 2.4 of the bookdown book

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

    如果您想对数字进行编号或交叉引用,则不支持下划线。

    【讨论】:

      猜你喜欢
      • 2022-01-19
      • 2011-04-29
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      • 2019-05-28
      • 2021-08-16
      • 2011-12-02
      • 1970-01-01
      相关资源
      最近更新 更多