使用xtable或knitr :: kable抑制.Rmd文件中的自动表名和编号

ves*_*and 8 latex r xtable rstudio knitr

Table 1:...在使用xtable()knitr::kable()在.Rmd文件中时,我想从R脚本中命名我的表而没有自动前缀.输出是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"))
```
Run Code Online (Sandbox Code Playgroud)

我已经看到了一些建议,类似的问题在这里,但我似乎无法得到它在.Rmd文件工作.

ves*_*and 10

事实证明我需要在YAML部分添加以下内容:

header-includes:
    - \usepackage{caption}
Run Code Online (Sandbox Code Playgroud)

以及代码块之前的某个地方:

\captionsetup[table]{labelformat=empty}
Run Code Online (Sandbox Code Playgroud)

它现在有效:

---
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"))
```
Run Code Online (Sandbox Code Playgroud)

这也在这里描述:

在markdown中使用texreg删除字幕

是的,我有点尴尬,我没有立即找到答案.

无论如何,感谢daroczig指向我在tex方向,而不是尝试使用块选项或类似的东西来解决问题.


小智 5

如果您还希望以相同的方式显示数字,请通过vestland 将示例修改为

---
title: "Suppress automatic table name and number"
output: pdf_document
header-includes:
    - \usepackage[labelformat=empty]{caption}
---
Run Code Online (Sandbox Code Playgroud)

并跳过\captionsetup{}.