Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/davidgohel/flextable/llms.txt

Use this file to discover all available pages before exploring further.

Three functions manage the global flextable defaults:
  • set_flextable_defaults() — override one or more defaults
  • get_flextable_defaults() — retrieve the current defaults as a list
  • init_flextable_defaults() — reset all defaults to package values

set_flextable_defaults()

set_flextable_defaults(
  font.family = NULL,
  font.size = NULL,
  font.color = NULL,
  text.align = NULL,
  padding = NULL,
  padding.bottom = NULL,
  padding.top = NULL,
  padding.left = NULL,
  padding.right = NULL,
  border.color = NULL,
  border.width = NULL,
  background.color = NULL,
  line_spacing = NULL,
  table.layout = NULL,
  cs.family = NULL,
  eastasia.family = NULL,
  hansi.family = NULL,
  decimal.mark = NULL,
  big.mark = NULL,
  digits = NULL,
  pct_digits = NULL,
  na_str = NULL,
  nan_str = NULL,
  fmt_date = NULL,
  fmt_datetime = NULL,
  extra_css = NULL,
  scroll = NULL,
  table_align = "center",
  split = NULL,
  keep_with_next = NULL,
  tabcolsep = NULL,
  arraystretch = NULL,
  float = NULL,
  fonts_ignore = NULL,
  theme_fun = NULL,
  post_process_all = NULL,
  post_process_pdf = NULL,
  post_process_docx = NULL,
  post_process_html = NULL,
  post_process_pptx = NULL,
  ...
)

Return value

A list of the previous default values. You can pass this list to do.call(set_flextable_defaults, old) to restore the previous state.

Parameters

Typography

font.family
string
Font family for characters in the Unicode range U+0000–U+007F. In Word output, set hansi.family to the same value to support non-ASCII characters.
font.size
numeric
Font size in points. Must be 0 or a positive integer.
font.color
string
Font color as a valid color string (e.g., "#000000" or "black").
cs.family
string
Word only. Font for complex script Unicode ranges (e.g., Arabic text using "Arial Unicode MS").
eastasia.family
string
Word only. Font for East Asian Unicode ranges (e.g., Japanese text using "MS Mincho").
hansi.family
string
Word only. Font for Unicode ranges not covered by other categories.
line_spacing
numeric
Line spacing multiplier. 1 is single spacing; 2 is double spacing.

Alignment and padding

text.align
string
Default text alignment: "left", "right", "center", or "justify".
padding
numeric
Shortcut that sets all four cell paddings (top, bottom, left, right) at once.
padding.bottom
numeric
Bottom cell padding in points.
padding.top
numeric
Top cell padding in points.
padding.left
numeric
Left cell padding in points.
padding.right
numeric
Right cell padding in points.

Borders and background

border.color
string
Default border color (e.g., "#000000" or "black").
border.width
numeric
Default border width in points.
background.color
string
Default cell background color.

Number and date formatting

decimal.mark
string
Decimal separator used by colformat_double(), colformat_num(). See formatC().
big.mark
string
Thousands separator used by colformat_double(), colformat_int(), colformat_num(). See formatC().
digits
integer
Number of decimal digits used by colformat_double(). See formatC().
pct_digits
integer
Number of digits for percentage formatting.
na_str
string
String displayed in place of NA values.
nan_str
string
String displayed in place of NaN values.
fmt_date
string
Date format string for colformat_date(). Follows strptime() syntax. Default: "%Y-%m-%d".
fmt_datetime
string
Datetime format string for colformat_datetime(). Follows strptime() syntax. Default: "%Y-%m-%d %H:%M:%S".

Table layout

table.layout
string
Column-width algorithm: "autofit" (default) or "fixed".
table_align
string
default:"center"
Default horizontal alignment of the table on the page: "left", "center", or "right".

Word-specific

split
logical
If TRUE, enables the Word option “Allow row to break across pages”.
keep_with_next
logical
Default for the paginate() function’s “keep rows together” option.

PDF (LaTeX) specific

tabcolsep
numeric
Space between cell content and the left/right cell border.
arraystretch
numeric
Row height relative to default height. Default: 1.5.
float
string
Floating placement in PDF: "none" (default, inline), "float" (float to best position), "wrap-r", "wrap-l", "wrap-i", or "wrap-o" (text wrapping variants).
fonts_ignore
logical
If TRUE, allows pdflatex to be used instead of xelatex or lualatex. Fonts are ignored because pdflatex does not support them.

HTML-specific

extra_css
string
Additional CSS instructions to inject into the table’s HTML output.
scroll
NULL | list
NULL for no scroll, or a list to enable a scroll box. See the scroll element of opts_html in set_table_properties().

Themes and post-processing

theme_fun
string | function
A theme function name (character) or function applied automatically to each new flextable. Applied as the last step inside flextable().
post_process_all
function
A function applied to every flextable before output, regardless of format. Runs before any format-specific post-processing.
post_process_pdf
function
A function applied just before the table is printed to PDF.
post_process_docx
function
A function applied just before the table is printed to Word.
post_process_html
function
A function applied just before the table is printed to HTML.
post_process_pptx
function
A function applied just before the table is printed to PowerPoint.

get_flextable_defaults()

Retrieve the current global defaults as a named list.
get_flextable_defaults()

Example

defaults <- get_flextable_defaults()
defaults$font.family
defaults$digits

init_flextable_defaults()

Reset all global defaults to the package’s built-in values.
init_flextable_defaults()

Examples

Change font color and border color, then restore the previous state:
ft_1 <- qflextable(head(airquality))
ft_1

old <- set_flextable_defaults(
  font.color   = "#AA8855",
  border.color = "#8855AA"
)
ft_2 <- qflextable(head(airquality))
ft_2

do.call(set_flextable_defaults, old)
Set a default theme applied at creation time:
set_flextable_defaults(theme_fun = theme_vanilla)
ft <- flextable(head(mtcars))  # theme_vanilla is applied automatically
ft
init_flextable_defaults()
Apply a theme automatically at print time (captures all added rows):
set_flextable_defaults(post_process_html = theme_booktabs)

See also

Build docs developers (and LLMs) love