Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a caption to a Kable Table in R Markdown

Tags:

r

r-markdown

I am using RMarkdown to write some university work I have created a table using the code below and need to export it to Microsoft Word

Can anyone tell me how to add a label describing the data in the table or do I have to do this in MS Word afterwards

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

    kable(table(Rawdata$Var1, Rawdata$Var2))
like image 487
John Smith Avatar asked Jul 02 '16 11:07

John Smith


1 Answers

Use the caption argument in kable.

If you want more options for formatting tables in Word output, I would recommend downloading the Gmisc package and using the Gmisc::docx_document format. Just keep in mind that it will save the file as an HTML file that can be opened as a Word Document and preserve the formatting.

For example:

---
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")
```
like image 179
Benjamin Avatar answered Oct 29 '22 19:10

Benjamin