huxtable-FAQ: Frequently Asked Questions, including how to get help

huxtable-FAQR Documentation

Frequently Asked Questions, including how to get help


A FAQ of common issues.


  • I get a LaTeX error when I try to compile my document!

    Have you installed the LaTeX packages you need? LaTeX packages are different from R packages. Run check_latex_dependencies() to find out if you are missing any. Then install them using your system's LaTeX management application. Or you can try install_latex_dependencies().

    In some rmarkdown and LaTeX formats, you also need to add LaTeX dependencies manually. Run report_latex_dependencies() and add the output to your LaTeX preamble, or in Rmarkdown formats, add it to the rmarkdown header like this:

      - \usepackage{array}
      - \usepackage{caption}
      ... et cetera
  • Huxtable isn't working in my Rmarkdown beamer_presentation slides.

    You may need to set the beamer "fragile" option, like this:

    # Slide title {.fragile}
  • Numbers in my cells look weird!

    You can change numeric formatting using number_format(). Base R options like scipen usually have no effect.

  • How can I use HTML, TeX etc. in my table?

    Use escape_contents():

    jams |>
         add_footnote("These jams are <i>tasty</i>!") |>
         set_escape_contents(final(1), everywhere, FALSE) |>

    Alternatively you might consider using markdown in cells, with set_markdown_contents().

  • I ran caption(ht) <- "Something" and got an error message:

    Error in UseMethod("caption<-") :
    no applicable method for 'caption<-' applied to an object of class "c('huxtable',   'data.frame')"

    You may have loaded another package with a caption method, e.g. "xtable". Try loading huxtable after xtable.

  • How can I get line breaks in my cells?

    Just insert a line break "\n" in the cell contents. Then make sure that width() is set and wrap() is TRUE (it is by default).

  • How can I change the font size, font etc. of captions?

    There are no direct commands for this. You have to use raw HTML/TeX/other commands within the caption itself. For example to have a bold caption in HTML, you might do something like:

    set_caption(jams, "<b>Jam Prices</b>")
  • How do I refer to tables in bookdown?

    As of version 4.3.0, this is handled automatically for you. Just set the label using label(), then in markdown text do e.g.:

  • I called library(huxtable) and now my data.table objects are getting printed!

    Set options(huxtable.knit_print_df = FALSE).

  • How can I set a property on an arbitrary group of cells?

    If you can't use the mapping-functions interface, and you want to set a property for multiple cells that aren't all in the same rows and/or columns, you could use a little-known fact about R subsetting. If you subset ht[x] where x is two-column numeric matrix, then each row of x indexes a single (row, column) cell. So, for example, here's how to set the background color of cells (2,1), (1, 3) and (4, 2) of a huxtable:

    indices <- matrix(c(2, 1, 1, 3, 4, 2), ncol = 2, byrow = TRUE)
    background_color(jams)[indices] <- "orange"

    Another useful trick sets properties on the diagonal, using diag():

    diag(background_color(jams)) <- "grey"
  • I have another problem.

    If you have a bug - i.e. there is something wrong with the software - or a feature request, please report it to Otherwise, ask a question on StackOverflow or That way, other people will benefit from the answers you get.

  • Can I email you directly?

    I'd rather you asked on a public website. If you then email me a link, I may be able to help.

huxtable documentation built on Dec. 28, 2022, 1:09 a.m.