flextable can be rendered as a raster or vector image using R’s grid graphics system. This is useful for including tables in presentations, reports, or composite figures.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.
Save as PNG or SVG
save_as_image() saves a flextable to a PNG or SVG file. The output format is determined by the file extension:
svglite package must be installed:
| Parameter | Description | Default |
|---|---|---|
x | A flextable object | |
path | Output path ending in .png or .svg | |
expand | White space (px) to add around the table | 10 |
res | Resolution of the PNG device (DPI) | 200 |
Captions set with
set_caption() are not included in image output. Captions are only rendered in document formats (Word, HTML, PDF).Convert to a grid grob with gen_grob()
gen_grob() converts a flextable to a grob (grid graphics object). This is the function used internally by save_as_image() and the patchwork integration.
fit argument
Controls how the table adapts to the drawing surface:
| Value | Behavior |
|---|---|
"auto" (default) | Resize table proportionally to fill the viewport |
"width" | Resize columns to fit viewport width; row heights unchanged |
"fixed" | Use exact column widths and row heights from the table |
scaling argument
Controls how text and content sizes respond to viewport size:
| Value | Behavior |
|---|---|
"min" (default) | Scale content down when viewport is smaller; do not scale up |
"full" | Scale content up or down to match viewport |
"fixed" | Never scale content |
just argument
Justification of the viewport layout within the drawing area. Accepts the same values as grid::grid.layout(just = ...). When NULL (default), justification is derived from fit.
wrapping argument
When TRUE (default), text wraps at word boundaries. When FALSE, text only wraps at explicit newline characters.
Getting dimensions
Use thedim() method on the grob to retrieve the rendered table size in inches:
Equations (
as_equation()) and hyperlinks (officer::hyperlink_ftext()) are not rendered by gen_grob(). Use a ragg, svglite, or ggiraph device for correct rendering.Combine with ggplot2 using patchwork
wrap_flextable() wraps a flextable as a patchwork-compatible patch, so it can be combined with ggplot2 plots using +, |, or / operators.
wrap_flextable() parameters
| Parameter | Description | Default |
|---|---|---|
x | A flextable object | |
panel | Table region aligned with the plot panel: "body", "full", "rows", "cols" | "body" |
space | How table dimensions influence layout: "free", "free_x", "free_y", "fixed" | "free" |
n_row_headers | Number of leading columns treated as row headers | 0 |
flex_body | Stretch body row heights to match adjacent plot panel height | FALSE |
flex_cols | Stretch data column widths to match adjacent plot panel width | FALSE |
expand | Expansion matching ggplot2::expansion(add = expand) for discrete axes | 0.6 |
just | Horizontal alignment within panel: "left", "right", "center" | "left" |
wrap_flextable() is experimental and the API may change in future versions. It requires the patchwork and gtable packages.Direct ggplot2 addition
You can also add a flextable directly to a ggplot2 object using+. This calls wrap_flextable() automatically with default settings: