Hao Zhu | 67764aa | 2019-03-15 11:57:50 -0400 | [diff] [blame] | 1 | --- |
| 2 | title: "xtable & kableExtra" |
| 3 | author: "Hao" |
| 4 | date: "2/13/2019" |
| 5 | output: pdf_document |
| 6 | --- |
| 7 | |
| 8 | ```{r setup, include=FALSE} |
| 9 | knitr::opts_chunk$set(message = FALSE) |
| 10 | ``` |
| 11 | |
| 12 | Recent versions of kableExtra (since 1.0) offers a function `xtable2kable`, which, as suggested by its name, turns a `xtable` object to a `kable` object so you can use functions in kableExtra after that. I tested some basic examples and it seem to work. |
| 13 | |
| 14 | ```{r} |
| 15 | library(xtable) |
| 16 | library(kableExtra) |
| 17 | |
| 18 | xtable(mtcars[1:5, 1:5]) %>% |
| 19 | xtable2kable() %>% |
| 20 | column_spec(1, width = "5cm") |
| 21 | ``` |
| 22 | |
| 23 | ```{r} |
| 24 | xtable(mtcars[1:5, 1:5], caption = "Some long caption") %>% |
| 25 | xtable2kable(caption.width = "10em") %>% |
| 26 | column_spec(1, color = "red") |
| 27 | ``` |
| 28 | |
| 29 | |
| 30 | |