Skip to main content
Themes apply a consistent set of borders, background colors, text styles, and alignment rules to a flextable in a single function call. flextable ships with several built-in themes covering everything from minimal academic styles to dark-mode designs.

How themes work

Theme functions are not like ggplot2 themes. They apply formatting to the table immediately at the time they are called, not dynamically as elements are added later.Apply a theme after all rows, headers, and footers have been added. Any rows or columns added after the theme call will not inherit the theme’s formatting.
library(flextable)

# Correct: add all structure first, then apply the theme
ft <- flextable(head(airquality))
ft <- add_footer_lines(ft, "Source: NYDEC")
ft <- theme_vanilla(ft)
ft

Available themes

theme_vanilla() — clean with horizontal rules

External horizontal lines are 2 pts thick; inner horizontal lines are 0.5 pt. Header text is bold. Text columns are left-aligned; numeric columns are right-aligned.
ft <- flextable(head(airquality))
ft <- theme_vanilla(ft)
ft

theme_booktabs() — LaTeX booktabs style

Top and bottom lines of the header and body are 2 pts thick; inner header lines are 0.5 pt. No vertical rules. Matches the LaTeX booktabs package aesthetic.
ft <- flextable(head(airquality))
ft <- theme_booktabs(ft)
ft
Pass bold_header = TRUE to bold the header row:
ft <- theme_booktabs(ft, bold_header = TRUE)

theme_box() — full grid

A complete grid with borders on every cell edge, inner and outer. Header is bold; footer is italic.
ft <- flextable(head(airquality))
ft <- theme_box(ft)
ft

theme_borderless() — no borders

All borders are removed. Header text is bold. Text columns are left-aligned; numeric columns are right-aligned.
ft <- flextable(head(airquality))
ft <- theme_borderless(ft)
ft

theme_zebra() — alternating row colors

Alternating background colors in the header and body. Default colors are #CFCFCF for odd header rows and #EFEFEF for odd body rows; even rows are transparent.
ft <- flextable(head(airquality))
ft <- theme_zebra(ft)
ft
Customize the four colors:
ft <- theme_zebra(
  ft,
  odd_header  = "#4472C4",
  odd_body    = "#D9E1F2",
  even_header = "#2E75B6",
  even_body   = "transparent"
)

theme_alafoli() — minimal with gray text

No background color. All text is #666666. No bold or italic. A single horizontal rule below the header. Compact 3 pt padding.
ft <- flextable(head(airquality))
ft <- theme_alafoli(ft)
ft

theme_apa() — APA style

APA (American Psychological Association) style: Times New Roman font, double line spacing, horizontal rules at top, below the header, and at the bottom of the body, centered alignment, and numbers formatted to 2 decimal places.
ft <- flextable(head(mtcars * 22.22))
ft <- theme_apa(ft)
ft

theme_tron() and theme_tron_legacy() — dark themes

Both use a dark background. Header text is orange/amber; body text is cyan/yellow. All borders are teal/blue.
ft <- flextable(head(airquality))
ft <- theme_tron(ft)
ft
ThemeBackgroundHeader colorBody colorBorder color
theme_tron#000000#ec9346#a4cee5#a4cee5
theme_tron_legacy#0C141F#DF740C#FFE64D#6FC3DF

theme_vader() — dark with red accents

Dark #242424 background, light #dfdfdf text. A thick red (#ff0000) horizontal rule separates the header from the body.
ft <- flextable(head(airquality))
ft <- theme_vader(ft)
ft

Setting a default theme

Use set_flextable_defaults() to apply a theme automatically to every new flextable created in the session:
set_flextable_defaults(theme_fun = theme_booktabs)

# All subsequent flextable() calls will apply theme_booktabs automatically
ft1 <- flextable(head(iris))
ft2 <- flextable(head(mtcars))
theme_fun is called as the last instruction inside flextable(). This means headers and footers added after the flextable() call are not formatted by the default theme. To apply a theme after headers and footers have been added, use the post_process_html (or post_process_docx, post_process_pptx, post_process_pdf) argument instead:
set_flextable_defaults(
  post_process_html = function(ft) {
    theme_vanilla(ft)
  }
)
The post-process function runs just before printing, so it sees the fully constructed table including any headers or footers added after flextable().
Be careful that post-process themes do not override formatting you applied explicitly before printing.

Theme summary

ThemeBordersBackgroundHeader style
theme_vanillaHorizontal onlyNoneBold
theme_booktabsTop / mid / bottomNoneOptional bold
theme_boxFull gridNoneBold
theme_borderlessNoneNoneBold
theme_zebraNoneAlternatingBold
theme_alafoliHeader bottom onlyNoneGray text
theme_apaTop, header bottom, body bottomNoneCentered
theme_tronFull grid (teal)BlackOrange, bold
theme_tron_legacyFull grid (teal)Dark navyAmber, bold
theme_vaderRed accent linesDark grayBold