【问题标题】:How to suppress automatic table name and number in an .Rmd file using xtable or knitr::kable?如何使用 xtable 或 knitr::kable 抑制 .Rmd 文件中的自动表名称和编号?
【发布时间】:2015-09-19 20:09:18
【问题描述】:

当在 .Rmd 文件中使用 xtable()knitr::kable() 时,我想从 R 脚本中命名我的表,而不使用自动 Table 1:... 前缀。输出为 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 文件中工作。

【问题讨论】:

  • IMO 这不是一个 R,而是一个 LaTeX 问题,可以在序言中回答类似 \captionsetup{labelformat=empty} 的问题。
  • 好的,但是如何将它包含在 .Rmd 文件中?在 YAML 标头中?
  • @daroczig 感谢您的提示。我一直在搞乱诸如 fig.lp = '' 之类的块设置以及您提到的来源中的其他内容。以及在 YAML 部分尝试不同的东西,但到目前为止没有成功。大多数示例似乎是“纯” LaTeX 示例,而不是应用 LaTeX 函数的针织降价(我什至不知道这是否有意义)。关于如何使用 markdown 将 \captionsetup{labelformat=empty} 压缩到 YAML 部分或块选项中的任何其他建议都是很好的。无论如何,感谢您到目前为止的帮助。

标签: r latex rstudio knitr xtable


【解决方案1】:

原来我需要在 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 方向,而不是尝试使用块选项或类似的东西来解决问题。

【讨论】:

    【解决方案2】:

    如果你也想用同样的方式来绘制图形,可以将 vestland 的示例修改为

    ---
    title: "Suppress automatic table name and number"
    output: pdf_document
    header-includes:
        - \usepackage[labelformat=empty]{caption}
    ---
    

    并跳过\captionsetup{}

    【讨论】:

      猜你喜欢
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多