kableExtra (version 1.3.4)

kable_styling: HTML table attributes


This function provides a cleaner approach to modify the style of HTML tables other than using the table.attr option in knitr::kable(). Note that those bootstrap options requires Twitter bootstrap theme, which is not avaiable in some customized template being loaded.


  bootstrap_options = "basic",
  latex_options = "basic",
  full_width = NULL,
  position = "center",
  font_size = NULL,
  row_label_position = "l",
  repeat_header_text = "\\textit{(continued)}",
  repeat_header_method = c("append", "replace"),
  repeat_header_continued = FALSE,
  stripe_color = "gray!6",
  stripe_index = NULL,
  latex_table_env = NULL,
  protect_latex = TRUE,
  table.envir = "table",
  fixed_thead = FALSE,
  htmltable_class = NULL,
  html_font = NULL,
  wraptable_width = "0pt"



Output of knitr::kable() with format specified


A character vector for bootstrap table options. Please see package vignette or visit the w3schools' Bootstrap Page for more information. Possible options include basic, striped, bordered, hover, condensed, responsive and none.


A character vector for LaTeX table options. Please see package vignette for more information. Possible options include basic, striped, hold_position, HOLD_position, scale_down & repeat_header. striped will add alternative row colors to the table. It will imports LaTeX package xcolor if enabled. hold_position will "hold" the floating table to the exact position. It is useful when the LaTeX table is contained in a table environment after you specified captions in kable(). It will force the table to stay in the position where it was created in the document. A stronger version: HOLD_position requires the float package and specifies [H]. scale_down is useful for super wide table. It will automatically adjust the table to page width. repeat_header in only meaningful in a longtable environment. It will let the header row repeat on every page in that long table.


A TRUE or FALSE variable controlling whether the HTML table should have 100\ the preferable format for full_width. If not specified, a HTML table will have full width by default but this option will be set to FALSE for a LaTeX table


A character string determining how to position the table on a page. Possible values include left, center, right, float_left and float_right. Please see the package doc site for demonstrations. For a LaTeX table, if float_* is selected, LaTeX package wrapfig will be imported.


A numeric input for table font size


A character string determining the justification of the row labels in a table. Possible values inclued l for left, c for center, and r for right. The default value is l for left justifcation.


LaTeX option. A text string you want to append on or replace the caption.


LaTeX option, can either be append(default) or replace


T/F or a text string. Whether or not to put a continued mark on the second page of longtable. If you put in text, we will use this text as the "continued" mark.


LaTeX option allowing users to pick a different color for their strip lines. This option is not available in HTML


LaTeX option allowing users to customize which rows should have stripe color.


LaTeX option. A character string to define customized table environment such as tabu or tabularx.You shouldn't expect all features could be supported in self-defined environments.


If TRUE, LaTeX code embedded between dollar signs will be protected from HTML escaping.


LaTeX floating table environment. kable_style will put a plain no-caption table in a table environment in order to center the table. You can specify this option to things like table* or float* based on your need.


HTML table option so table header row is fixed at top. Values can be either T/F or list(enabled = T/F, background = "anycolor").


Options to use the in-house lightable themes. Choices include lightable-minimal, lightable-classic, lightable-classic-2, lightable-material, lightable-striped and lightable-hover. If you have your customized style sheet loaded which defines your own table class, you can also load it here.


A string for HTML css font. For example, html_font = '"Arial Narrow", arial, helvetica, sans-serif'.


Width of the wraptable area if you specify "float_left/right" for latex table. Default is "0pt" for automated determination but you may specify it manually.


For LaTeX, if you use other than English environment

  • all tables are converted to 'UTF-8'. If you use, for example, Hungarian characters on a Windows machine, make sure to use Sys.setlocale("LC_ALL","Hungarian") to avoid unexpected conversions.

  • protect_latex = TRUE has no effect.


  • protect_latex = TRUE is for including complicated math in HTML output. The LaTeX may not include dollar signs even if they are escaped. Pandoc's rules for recognizing embedded LaTeX are used.


Run this code
x_html <- knitr::kable(head(mtcars), "html")
kable_styling(x_html, "striped", position = "left", font_size = 7)

x_latex <- knitr::kable(head(mtcars), "latex")
kable_styling(x_latex, latex_options = "striped", position = "float_left")
# }
# }

Run the code above in your browser using DataCamp Workspace