Huxtable is an R package to create LaTeX and HTML tables, with a friendly, modern interface. Features include control over text styling, number format, background color, borders, padding and alignment. Cells can span multiple rows and/or columns. Tables can be manipulated with standard R subsetting or dplyr functions. Here are some quick examples:

ht <- hux(
        Employee = c('John Smith', 'Jane Doe', 'David Hugh-Jones'),
        Salary = c(50000, 50000, 40000),
        add_colnames = TRUE

bold(ht)[1,]           <- TRUE
bottom_border(ht)[1,]  <- 0.4
align(ht)[,2]          <- 'right'
right_padding(ht)      <- 10
left_padding(ht)       <- 10
width(ht)              <- 0.35
number_format(ht)      <- 2

John Smith50000.00
Jane Doe50000.00
David Hugh-Jones40000.00
ht <- hux(
        Employee = c('John Smith', 'Jane Doe', 'David Hugh-Jones'),
        Salary = c(50000, 50000, 40000)

ht                                        %>%
      set_bold(1, everywhere)             %>%
      set_bottom_border(1, everywhere)    %>%
      set_align(everywhere, 2, 'right')   %>%
      set_lr_padding(10)                  %>%
      set_width(0.35)                     %>%
John Smith50000.00
Jane Doe50000.00
David Hugh-Jones40000.00
mtcars[1:5]                                                                           %>%
      as_huxtable(add_rownames = "Model")                                             %>%
      set_bold(1, everywhere, TRUE)                                                   %>%
      set_all_borders(1)                                                              %>%
      map_text_color(everywhere, "mpg",      by_colorspace("navy", "red", "yellow"))  %>%
      map_background_color(everywhere, "hp", by_quantiles(0.8, c("white", "yellow"))) %>%
      map_italic(everywhere, "Model",        by_regex("Merc.*" = TRUE))               %>%
Mazda RX421  61601103.9
Mazda RX4 Wag21  61601103.9
Datsun 71022.84108933.85
Hornet 4 Drive21.462581103.08
Hornet Sportabout18.783601753.15
Duster 36014.383602453.21
Merc 240D24.44147623.69
Merc 23022.84141953.92
Merc 28019.261681233.92
Merc 280C17.861681233.92
data(diamonds, package = 'ggplot2')

lm1 <- lm(log(price) ~ carat, diamonds)
lm2 <- lm(log(price) ~ depth, diamonds)
lm3 <- lm(log(price) ~ carat + depth, diamonds)

huxreg(lm1, lm2, lm3)
(Intercept)6.215 ***7.749 ***7.313 ***
(0.003)   (0.188)   (0.074)   
carat1.970 ***        1.971 ***
(0.004)           (0.004)   
depth        0.001    -0.018 ***
        (0.003)   (0.001)   
N53940        53940        53940        
R20.847    0.000    0.847    
logLik-26728.969    -77321.478    -26617.649    
AIC53463.939    154648.956    53243.298    
*** p < 0.001; ** p < 0.01; * p < 0.05.
# Files are produced in the current working directory.

To learn more, check out the vignette in HTML or PDF format, or the original R Markdown. Or, read the design principles behind huxtable, including a comparison with other R packages to create tables.


September 18, 2020: RStudio table contest

RStudio is running a competition to produce nice tables from R. I will be judging some of the entries. Download huxtable 5.1.0 (just released) and produce something amazing!

September 18, 2020: Huxtable 5.1.0 released

This release contains several bugfixes, and some backwards-compatible new features:

June 16, 2020: Huxtable 5.0.0 released

This release contains many changes and improvements. It also breaks backwards compatibility.

January 9, 2020: Huxtable 4.7.1 released

This release added caption support for as_flextable(). A new colwise argument for by_quantiles(), by_equal_groups() and by_colorspace() allows calculating quantiles or colors separately for each column.

In other news, the expss package now supports export to huxtables.

October 3, 2019: Huxtable 4.7.0 released

This release improves error messages and adds some new functionality:

insert_row(ht, "Header Text", fill = "", colspan = ncol(ht))

August 6, 2019: Huxtable 4.6.1 released

This release fixes two bugs, including one where cell borders around merged cells were misplaced in LaTeX.

June 12, 2019: Huxtable 4.6.0 released

This release fixes a few bugs, and adds one new feature: the ability to use portable font names across HTML and PDF, using the LaTeX fontspec package. To switch this on, set options(huxtable.latex_use_fontspec = TRUE).

March 19, 2019: Huxtable 4.5.0 released

This release fixes some CRAN bugs, and adds one new feature: a quick_latex() function to export data to a .tex file.

March 4, 2019: Huxtable 4.4.0 released

This release contains some incremental improvements:

November 7, 2018: Huxtable 4.3.0 released

This release contains several improvements:

Here's an example of using map_ functions to stripe a table, then pick out extreme values:

data <- matrix(rnorm(25), 5, 5)
as_hux(data) %>%
      set_outer_borders(0.4) %>%
      map_background_color(by_rows("grey95", "white")) %>%
      map_text_color(by_quantiles(c(0.1, 0.9), c("red", "black", "green3")))
1.86 -1.87 -1.32 0.9441.96 
0.386-0.921-0.239-0.64 -0.953
-1.47 1.2  -1.14 -2.18 -1.87 
0.132-1.8  -0.8280.58 0.792

October 26, 2018: Huxtable 4.2.1 released

This patch release works around a bug with recent pandoc versions, which led to huxtable's TeX commands being escaped in some rmarkdown documents.

To apply the workaround, you will need to add:

md_extensions: +raw_attribute

to your YAML header.

If you still have problems, please report a bug.

October 3, 2018: Huxtable 4.2.0 released

This minor point release adds a few features and bugfixes.

August 1, 2018: Huxtable 4.1.0 released

This minor point release focuses on bugfixes, speed and maintainability.

June 2, 2018: Huxtable 4.0.0 released

This release brings some changes. The most important are:

These are breaking changes, so you can set options to go back to the old behaviour.

One other change is being introduced gradually: add_colnames will be set to TRUE by default in a future release. To future-proof your code, you can enable this behaviour by setting options(huxtable.add_colnames = TRUE).

Other changes include a new theme_plain theme; automatically opening documents created by quick_pdf and friends; and several bugfixes. Please report any bugs in the usual place.

February 23, 2018: Huxtable 3.0.0 released

The major version bump marks a (small) change in the quick_xxx function API: if called without an explicit file argument, these functions will fail when called non-interactively, and will prompt before overwriting files if called interactively. This prevents nasty surprises.

Excel output is now supported using the openxlsx package. Those working in a corporate environment can now create formatted spreadsheets to make the pointy-haired boss happy.

You can now select columns using dplyr-style select helpers like matches() and starts_with() in set_* functions.

Huxtable logo in Excel
Printing the huxtable logo into an Excel spreadsheet

January 3, 2018: Huxtable 2.0.0 released

The major version bump marks a change in how numbers are shown. Numeric formatting via number_format now applies to any number found in a cell, even if there are non-numeric characters. This means that e.g. cells like "2.71 (1.4) **" will have both numbers formatted.

There are also new quick_pdf, quick_html and quick_docx functions, for quick output of data frames or similar objects in different formats.

October 2017: Huxtable 1.0.0 released!

New features include:

On-screen color
Going back to the 80s with on-screen color


From CRAN:


Development version from github:


The name

Huxtable could stand for "Happy User Xtable", or if you prefer, "Hyped Up Xtable", or for Germans maybe "Html Und teX Table".


The logo above was randomly generated by huxtable, using hux_logo(). The web page background is Piet Mondrian's Composition A.