flextable() creates a flextable object from a data frame. flextable objects support rich text formatting, cell merging, custom headers and footers, and export to Word, PowerPoint, HTML, PDF, and other formats.
A flextable is composed of three parts: header, body, and footer. Most formatting functions accept a part argument to target one or all parts.
Function signature
Parameters
A data frame. Also accepts
data.table and tibble objects, which are coerced to data.frame internally.Column names or keys to display. Names not present in
data are added as blank columns.Initial cell width in inches.
Initial cell height in inches.
Deprecated. Use
set_flextable_defaults() instead.Deprecated. Use
set_flextable_defaults() instead.If
TRUE, column labels and value labels present in the dataset (e.g., from haven or labelled packages) are used as display headers.Return value
An object of classflextable.
Special characters
flextable translates\n into a soft return (a line break within the same paragraph, not a new paragraph) and \t into a tab character. Tab rendering varies by output format:
- HTML — em space entity
- Word — native Word tab element
- PowerPoint — native PowerPoint tab element
- LaTeX —
\quad
Default formatting
Formatting defaults are applied automatically to every new flextable. Useset_flextable_defaults() to change them globally, init_flextable_defaults() to reset them, and get_flextable_defaults() to inspect the current values.
Examples
See also
qflextable()— quick flextable with fixed layout and autofitas_flextable()— convert other objects to flextableset_flextable_defaults()— set global defaultsstyle(),autofit(),theme_booktabs()