在 R Markdown 中为 Kable 表添加标题

Joh*_*ith 5 r r-markdown

我正在使用 RMarkdown 编写一些大学作业 我使用下面的代码创建了一个表格,需要将其导出到 Microsoft Word

谁能告诉我如何添加描述表中数据的标签,或者我是否必须在 MS Word 中执行此操作

    ---
    title: "Data"
    author: "foo"
    date: "2 July 2016"
    output:
      word_document:
    bibliography: bibliography.bib
    ---

    kable(table(Rawdata$Var1, Rawdata$Var2))
Run Code Online (Sandbox Code Playgroud)

Ben*_*min 10

使用中的caption参数kable

如果您需要更多选项来格式化 Word 输出中的表格,我建议您下载该Gmisc软件包并使用Gmisc::docx_document格式。请记住,它会将文件另存为 HTML 文件,该文件可以作为 Word 文档打开并保留格式。

例如:

---
title: "Data"
author: "foo"
date: "2 July 2016"
output:  Gmisc::docx_document
---

```{r}
knitr::kable(head(mtcars[, 1:3]),
             caption = "This is the table caption")
```
Run Code Online (Sandbox Code Playgroud)