如何使用xtable或knitr :: kable抑制.Rmd文件中的自动表名和编号? [英] How to suppress automatic table name and number in an .Rmd file using xtable or knitr::kable?

查看:101
本文介绍了如何使用xtable或knitr :: kable抑制.Rmd文件中的自动表名和编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在.Rmd文件中使用xtable()knitr::kable()时,我想从R脚本命名我的表而没有自动Table 1:...前缀.输出是pdf文档.

I'd like to name my tables from R scripts without the automatic Table 1:... prefix when using xtable() or knitr::kable() in an .Rmd file. Output is a pdf document.

这是一个来自.Rmd文件的可重现示例:

Here's a reproducible example from an .Rmd file:

---
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"))
```

我在这里,但似乎无法在.Rmd文件中使用它.

I've seen similar questions with some suggestions here, but I can't seem to get it to work in an .Rmd file.

推荐答案

原来,我需要在YAML部分中添加以下内容:

It turns out that I needed to add the following in the YAML section:

header-includes:
    - \usepackage{caption}

在代码块之前的位置加上以下内容:

AND the following somewhere before the code chunk:

\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"))
```

这里也对此进行了描述:

This has also been described here:

在markdown中使用texreg摆脱字幕

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

And yes, I'm a bit embarrased that I didn't find that answer straight away.

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

Anyway, thanks to daroczig for pointing me in the tex direction instead of trying to solve the problem using chunk options or something like that.

这篇关于如何使用xtable或knitr :: kable抑制.Rmd文件中的自动表名和编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆