How can I get captions on my table floats in pdf_document generated by rmarkdown?
Using
output:
pdf_document:
fig_caption: true
and
```{r, fig.cap='a caption'}
myplot
```
Generates a floating figure with myplot and the caption specified.
How do I achieve the same thing with tables generated by xtable?
```{r, results='asis', fig.cap='table caption'}
print(xtable(table), comment = FALSE)
```
I have tried using floating.environment = 'figure' in print.xtable, but to no avail.
You can add a caption to the table via the caption argument, e.g. (see Table 10.1 for the output), knitr::kable(iris2, caption = "An example table caption.") TABLE 10.1: An example table caption.
To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.
1 Table of contents. You can add a table of contents (TOC) using the toc option and specify the depth of headers that it applies to using the toc_depth option. For example: --- title: "Habits" output: html_document: toc: true toc_depth: 2 ---
Or similarly,
```{r results='asis'}
knitr::kable(head(mtcars), format = 'pandoc', caption = 'Title of the table')
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With