13.2 kableExtra

The kableExtra package (Zhu 2019) is designed to extend the basic functionality of tables produced using kable. As explained by the package author, the intention with using kableExtra is that you can:

  • Use default base kable() for all simple tables
  • Use kable() with kableExtra to generate 90 % of complex/advanced/self-customized/beautiful tables in either HTML or LaTeX
  • Only have to mess with raw HTML/LaTeX in the last 10% cases where kableExtra cannot solve the problem

This section aims to provide a quick overview of some of the main principles of kableExtra, and provides some examples of how you may wish to integrate it into your document. For extensive documentation, readers are recommended to check the documentation online, which provides full details on how the outputs can be customized for both HTML and LaTeX outputs.

13.2.1 Setup

kableExtra is available to download through CRAN:

# Install from CRAN

# install the development version

13.2.2 Customizing HTML

  • Width and position
  • column and row spec
  • bootstrap styling
  • Scroll box

13.2.3 Customizing PDF

  • Width and position
  • column and row spec
  • Styling
  • Landscape page

You can scale the width of the table using the function kable_styling(latex_options = "scale_down"). This will force the table to the width of the page.

kable(iris[1:5, ], format = "latex", booktabs = TRUE) %>% 
  kable_styling(latex_options = "scale_down")


Zhu, Hao. 2019. KableExtra: Construct Complex Table with ’Kable’ and Pipe Syntax. https://CRAN.R-project.org/package=kableExtra.