I want to use function knitr::kable()
in an RStudio notebook.
If column names are short, the spaces between columns are small and it makes information hard to understand (see figure below). It seems that padding
does not work in this situation. Is there a way to make spaces between the columns (indicated by yellow arrows) larger in RStudio notebooks?
library(magrittr)
iris %>%
setNames(c("A", "B", "C", "D", "E")) %>%
head() %>%
knitr::kable(padding = 20)
Add space to both left and right of the column in RStr_pad function along with width argument and side=”both” adds space to both the sides of the column.
By defining the table format and adding some CSS styling you can change the size of the like so: knitr::kable(x, format = "html", table. attr = "style='width:30%;'") . This may lead to loosing the table lines. kableExtra offer nice styling tools to add for instance lines.
The kable() function in knitr is a very simple table generator, and is simple by design. It only generates tables for strictly rectangular data such as matrices and data frames. You cannot heavily format the table cells or merge cells.
Description. A very simple table generator, and it is simple by design. It is not intended to replace any other R packages for making tables. The kable() function returns a single table for a single data object, and returns a table that contains multiple tables if the input object is a list of data objects.
You could use kableExtra
for nicer styling in general, including wider column spacing by default.
library(magrittr)
library(kableExtra)
iris %>%
setNames(c("A", "B", "C", "D", "E")) %>%
head() %>%
knitr::kable() %>%
kable_styling()
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