This package can be installed from CRAN as usual, or you may try the development version on GitHub ():

    It has extensive documentation at https://haozhu233.github.io/kableExtra/, which provides a lot of examples on how the kable() output can be customized for either HTML or LaTeX output. We recommend that you read its documentation by yourself, and will only present a handful of examples in this section.

    The kableExtra package features the pipe operator, %>%. You can pipe the kable() output to the styling functions of kableExtra, e.g.,

    1. library(knitr)
    2. kable(iris) %>%
    3. kable_styling(latex_options = "striped")

    The functions row_spec() and can be used to style individual rows and columns, respectively. In the example below, we make the first row bold and italic, add a black background to the second and third rows while changing the font color to white, underline the fourth row and change its typeface, rotate the fifth row, and strike out the fifth column:

    1. kable(head(iris, 5), align = 'c', booktabs = TRUE) %>%
    2. row_spec(1, bold = TRUE, italic = TRUE) %>%
    3. row_spec(2:3, color = 'white', background = 'black') %>%
    4. row_spec(4, underline = TRUE, monospace = TRUE) %>%
    5. column_spec(5, strikeout = TRUE)
    Sepal.LengthSepal.WidthPetal.LengthPetal.WidthSpecies
    5.13.51.40.2setosa
    4.93.01.40.2setosa
    4.73.21.30.2setosa
    4.63.11.50.2setosa
    5.03.61.40.2setosa

    Similarly, you can style individual cells with the cell_spec() function.

    Rows and columns can be grouped via the functions pack_rows() and add_header_above(), respectively. You can also collapse rows via collapse_rows(), so one cell can span multiple rows. Below is an example that shows a custom table header with grouped columns:

    Below is an example of pack_rows(). The meaning of its index argument is similar to the argument of add_header_above() as we just explained before.

    1. iris3 <- iris[c(1:2, 51:54, 101:103), ]
    2. kable(iris3[, 1:4], booktabs = TRUE) %>% pack_rows(
    3. index = c("setosa" = 2, "versicolor" = 4, "virginica" = 3)
    4. )
    Sepal.LengthSepal.WidthPetal.LengthPetal.Width
    setosa
    15.13.51.40.2
    24.93.01.40.2
    versicolor
    517.03.24.71.4
    526.43.24.51.5
    536.93.14.91.5
    545.52.34.01.3
    virginica
    1016.33.36.02.5
    1025.82.75.11.9
    1037.13.05.92.1

    There are a few features that are specific to the HTML or LaTeX output format. For example, landscape pages only make sense in LaTeX, so the landscape() function in kableExtra only works for LaTeX output. Below we show an example to scale down a table to fit the page (otherwise it would be too wide):

    mpgcyldisphpdratwtqsecvsamgearcarb
    Lotus Europa30.4495.11133.771.51316.91152
    Ford Pantera L15.88351.02644.223.17014.50154
    Ferrari Dino19.76145.01753.622.77015.50156
    Maserati Bora15.08301.03353.543.57014.60158
    Volvo 142E21.44121.01094.112.78018.61142

    You will not see any differences in the above two tables if you are viewing the HTML version.