flextable provides a set of convenience functions for changing text appearance. Each targets theDocumentation 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.
i rows and j columns you select inside a given part of the table.
Bold and italic
bold() and italic() each accept a boolean value and the standard selectors:
part = "body" and apply to all rows and columns when i and j are NULL.
Font color
color() sets the text color. Accepts any R color name or a hex string:
Using a color function
Whencolor is a function it is called once per source column and must return a character vector of color values the same length as the number of rows:
j is driven by values from a different (possibly hidden) column, pass that column name to source.
Font size
fontsize() sets the font size in points:
Font family
font() changes the typeface. The fontname string must refer to a font that is installed on the system:
font() also accepts cs.family, eastasia.family, and hansi.family for complex-script, East-Asian, and HAnsi ranges respectively — these only affect Word and PowerPoint output.
Use
gdtools::register_gfont() to load Google Fonts. For HTML output the font is injected automatically into the document.Text highlight
highlight() sets the background shading behind the text (distinct from the cell background set by bg()):
Using a highlight function
Formula selectors for conditional formatting
All text formatting functions support formula-based row selection. The formula is evaluated against the body dataset:Formula selectors (
i = ~ condition) only work with part = "body". Header and footer parts store character representations, so numeric conditions cannot be evaluated on them.Using fp_text() for full text control
When you need to set multiple text properties in one call, use style() with an officer::fp_text() object:
fp_text() properties:
| Property | Type | Description |
|---|---|---|
bold | logical | Bold weight |
italic | logical | Italic style |
underlined | logical | Underline |
color | character | Hex or R color name |
shading.color | character | Highlight color |
font.size | numeric | Size in points |
font.family | character | Font family name |
Underline and strikethrough
fp_text() supports underlined = TRUE and strike = TRUE. These are not available as standalone convenience functions — use style() with an fp_text() object:
Quick reference
| Function | Key argument | Default part |
|---|---|---|
bold(x, i, j, bold, part) | bold = TRUE | "body" |
italic(x, i, j, italic, part) | italic = TRUE | "body" |
color(x, i, j, color, part) | color (required) | "body" |
fontsize(x, i, j, size, part) | size = 11 | "body" |
font(x, i, j, fontname, part) | fontname (required) | "body" |
highlight(x, i, j, color, part) | color = "yellow" | "body" |