我想从没有自动 Table 1:...
的 R 脚本中命名我的表使用 xtable()
时的前缀或 knitr::kable()
在 .Rmd 文件中。输出为 pdf 文档。
这是 .Rmd 文件中的可重现示例:
---
title: "Suppress automatic table name and number"
output: pdf_document
---
```{r myirischunk, results = 'asis', tab.cap = NULL, echo = TRUE}
library(xtable)
print(knitr::kable(head(iris), caption = "I sure wish it would say Table 1.a"))
print(knitr::kable(head(iris), caption = "Please stop"))
print(xtable(head(iris), caption = "Same thing with xtable"))
```
我已经看到了类似的问题并提出了一些建议 here ,但我似乎无法让它在 .Rmd 文件中工作。
最佳答案
事实证明,我需要在 YAML 部分添加以下内容:
header-includes:
- \usepackage{caption}
以及代码块之前的某处:
\captionsetup[table]{labelformat=empty}
现在它起作用了:
---
title: "Suppress automatic table name and number"
output: pdf_document
header-includes:
- \usepackage{caption}
---
\captionsetup[table]{labelformat=empty}
```{r myirischunk, results = 'asis', tab.cap = NULL, echo = TRUE}
print(knitr::kable(head(iris), caption = "Table 21.a - My very own table name"))
```
此处也对此进行了描述:
Get rid of captions using texreg in markdown
是的,我有点尴尬,我没有立即找到答案。
无论如何,感谢 daroczig 将我指向 tex 方向,而不是尝试使用 block 选项或类似的东西来解决问题。
关于r - 如何使用 xtable 或 knitr::kable 抑制 .Rmd 文件中的自动表名称和编号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31182147/