【问题标题】:rmarkdown caption numbering/reference work with underscores?rmarkdown 标题编号/参考与下划线一起使用?
【发布时间】:2019-08-23 00:02:23
【问题描述】:

有没有其他人注意到如果引用使用下划线而不是连字符,rmarkdown 不会对表格标题进行编号?请参阅下面的 sn-p。或构建 this website 以获取工作示例。

---
title: "Table Captioning"
output:
  bookdown::html_document2:
    number_sections: true
    fig_caption: true
---

# Example

It works in table \@ref(tab:dummy-table) when using hypens.

Table: (\#tab:dummy-table) Some caption.
\```{r dummy-table, echo=FALSE}
knitr::kable(data.frame(a = letters[1:3], 
                        b = 1:3))
\```

But not in table \@ref(tab:dummy_table) when using underscores?

Table: (\#tab:dummy_table) Some caption.
\```{r dummy_table, echo=FALSE}
knitr::kable(data.frame(a = letters[4:6], 
                        b = 4:6))
\```

没什么大不了的,只是让我绊了一下。如果此行为记录在某处而我错过了,我们深表歉意。

【问题讨论】:

    标签: r latex r-markdown


    【解决方案1】:

    RMarkdown book 中的第 2.6 节建议下划线可能会给您带来麻烦:

    我强烈建议您只在标签中使用字母数字字符(a-z、A-Z 和 0-9)和破折号 (-),因为它们不是特殊字符,并且肯定适用于所有输出格式。尤其是其他字符、空格和下划线,可能会在某些包中引起问题,例如 bookdown。

    现在,由于您在 YAML 中的设置,您正在使用 bookdown

    output:
      bookdown::html_document2:
    

    您首先需要bookdown 选项才能使引用生效。默认的 rmarkdown html 输出将是 html_document 并且不适用于自动引用。换句话说:在 R 代码块标签中,下划线对你来说是禁止的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-06
      • 2017-10-16
      相关资源
      最近更新 更多