Abbas
Abbas

Reputation: 897

How to move the caption of table generated by kable function in Rmarkdown to the bottom?

The following simple code in Rmarkdown will generate a table with a caption on top.

library(dplyr)
df <- iris %>% head()
knitr::kable(df, caption = "Table caption is on the top")

The output

Is there any way to move the table caption generated by kable function to the bottom?

Upvotes: 1

Views: 1011

Answers (1)

Shafee
Shafee

Reputation: 19857

Try the package {xtable} which does put table caption at bottom and then pass the xtable object to kableExtra::xtable2kable to turn the xtable object into a kable object and then you have the caption at the bottom of the table.

```{r message=FALSE}

library(dplyr)
library(xtable)
library(kableExtra)

df <- iris %>% head()

xtable(df, caption = "Table caption is on the top") %>%
  xtable2kable()
```

The rendered output looks like

table_caption_at_bottom

To know more about this caption position issue, follow this issue-thread on Github.

Upvotes: 1

Related Questions