Skip to main content
flextable reads a global defaults object before rendering any table. Changing these defaults once — typically in a setup chunk — saves you from repeating the same arguments on every table.

Setting defaults

set_flextable_defaults() updates one or more defaults and returns the previous values invisibly. This lets you restore the original state with do.call().
library(flextable)

# Save old values and apply new ones
old <- set_flextable_defaults(
  font.color = "#AA8855",
  border.color = "#8855AA"
)

ft <- qflextable(head(airquality))
ft

# Restore previous values
do.call(set_flextable_defaults, old)

Parameter reference

Typography

ParameterDefaultDescription
font.familyOS-dependentFont for Unicode range U+0000–U+007F. Set to "Arial" on Windows, "Helvetica" on macOS, "DejaVu Sans" on Linux.
cs.familysame as font.familyComplex-script font (e.g. Arabic). Word output only.
eastasia.familysame as font.familyEast Asian font (e.g. Japanese). Word output only.
hansi.familysame as font.familyHigh ANSI font for characters not covered by other ranges. Word output only.
font.size11Font size in points.
font.color"black"Font color; any R color name or hex string.
line_spacing1Line spacing multiplier. 1 = single, 2 = double.
When outputting to Word with non-ASCII characters, set both font.family and hansi.family to the same font name.

Alignment and padding

ParameterDefaultDescription
text.align"left"Cell text alignment. One of "left", "right", "center", "justify".
paddingShortcut that sets all four padding values at once.
padding.bottom5Bottom padding in points.
padding.top5Top padding in points.
padding.left5Left padding in points.
padding.right5Right padding in points.

Borders and background

ParameterDefaultDescription
border.color"#666666"Border color.
border.width0.75Border width in points.
background.color"transparent"Cell background color.

Table layout and alignment

ParameterDefaultDescription
table.layout"fixed"Column-width algorithm. "fixed" or "autofit".
table_align"center"Horizontal alignment of the table itself. "left", "center", or "right".

Number formatting

ParameterDefaultDescription
decimal.mark"."Decimal separator used by colformat_num() / colformat_double().
big.mark","Thousands separator.
digits1Number of decimal digits for colformat_double().
pct_digits1Decimal digits for percentage columns.
na_str""String shown in place of NA.
nan_str""String shown in place of NaN.
fmt_date"%Y-%m-%d"Date format string; see ?strptime.
fmt_datetime"%Y-%m-%d %H:%M:%S"Datetime format string.

HTML-specific

ParameterDefaultDescription
extra_css""Additional CSS injected into the table’s <style> block.
scrollNULLPass a list to enable a scrollable HTML box. See scroll in set_table_properties().

PDF / LaTeX-specific

ParameterDefaultDescription
fonts_ignoreFALSESet to TRUE when using pdflatex, which cannot embed custom fonts. xelatex and lualatex support fonts normally.
tabcolsep2Space between text and the left/right cell border (LaTeX).
arraystretch1.5Row height multiplier relative to default (LaTeX).
float"none"PDF float placement. Options: "none", "float", "wrap-r", "wrap-l", "wrap-i", "wrap-o".

Word-specific

ParameterDefaultDescription
splitTRUEAllow rows to break across pages ("Allow row to break across pages" in Word).
keep_with_nextFALSEDefault for the paginate() function’s keep-rows-together option.

Theme

ParameterDefaultDescription
theme_fun"theme_booktabs"Name of the default theme function, or a theme function itself. Applied to every new flextable.

Post-processing hooks

Post-processing functions run just before the table is rendered. Use them to apply output-specific modifications without repeating yourself.
ParameterDescription
post_process_allRuns first, before any output-specific hook.
post_process_pdfRuns for PDF output only.
post_process_docxRuns for Word output only.
post_process_htmlRuns for HTML output only.
post_process_pptxRuns for PowerPoint output only.
Each function receives the flextable object and must return a flextable object.
# Add a footer line only in Word
set_flextable_defaults(
  post_process_docx = function(ft) {
    add_footer_lines(ft, "Source: internal data")
  }
)

Retrieving current defaults

get_flextable_defaults() returns the current defaults as a named list:
get_flextable_defaults()
Printing the result shows a structured summary grouped by style properties, cell content settings, table layout, and theme.

Resetting to package defaults

init_flextable_defaults() discards any customizations and restores the original package defaults:
init_flextable_defaults()
Call this at the end of an example or test to avoid leaking state.

Best practice: setup chunk

Set your defaults once in the document setup chunk so every table in the document inherits them:
library(flextable)

set_flextable_defaults(
  font.size = 10,
  font.family = "Arial",
  padding = 3,
  table.layout = "autofit",
  border.color = "#444444",
  na_str = "—"
)
Use fp_text_default() and fp_border_default() when building custom chunks or borders — they automatically read from the active defaults so your custom styles stay in sync with the rest of the table.

Default-aware helper objects

fp_text_default() creates an officer::fp_text() object pre-filled with the current font family, size, and color. Only override the properties you need:
set_flextable_defaults(
  font.size = 11, font.color = "#303030",
  padding = 3, table.layout = "autofit"
)

z <- flextable(head(cars))

z <- compose(
  x = z,
  i = ~ speed < 6,
  j = "speed",
  value = as_paragraph(
    as_chunk("slow... ", props = fp_text_default(color = "red")),
    as_chunk(speed, props = fp_text_default(italic = TRUE))
  )
)
z

init_flextable_defaults()
Similarly, fp_border_default() creates an officer::fp_border() using the current border color and width:
set_flextable_defaults(border.color = "orange")

z <- flextable(head(cars))
z <- theme_vanilla(z)
z <- vline(z, j = 2, part = "all", border = fp_border_default())
z

init_flextable_defaults()