autofit()
Computes and applies optimised column widths and row heights based on the minimum size required to display each cell’s content on one line.
autofit() is not the same as the Microsoft Word Autofit feature. It calculates minimum content widths and applies them as fixed widths. If you need a percentage-based responsive layout, use set_table_properties(layout = "autofit") instead.When autofit() is used with rotated text, rotation is ignored in the size calculation. Use dim_pretty() and width() manually in that case.A
flextable object.Extra width to add to each column, in the unit specified by
unit.Extra height to add to each row, in the unit specified by
unit.Which parts to include in the size calculation:
"body", "header", "footer", or "all".Unit for
add_w and add_h. One of "in" (inches), "cm", or "mm".How to treat horizontally spanned (merged) cells in the width calculation:
"none"— merged cells contribute 0 width (do not influence column widths)."divided"— merged cell width is divided equally among the spanned columns."included"— merged cell widths are included as-is in the calculation.
Example
dim_pretty()
Returns the minimum estimated column widths and row heights without applying them to the table. Use this to inspect sizes before manually calling width() or height().
A
flextable object.Which parts to include:
"body", "header", "footer", or "all".Unit for returned values. One of
"in" (inches), "cm", or "mm".How to treat horizontally spanned cells. Same values as for
autofit().Return value
A list with two elements:widths— numeric vector of minimum column widths.heights— numeric vector of minimum row heights.
Example
fit_to_width()
Shrinks the table to fit within a maximum total width by iteratively decreasing font sizes until the table fits.
A
flextable object.Maximum total width the table should occupy.
Amount to decrease the font size (in points) at each iteration.
Maximum number of shrink iterations before stopping.
Unit for
max_width. One of "in" (inches), "cm", or "mm".Example
flextable_dim()
Returns the overall width, height, and aspect ratio of the table as a named list.
A
flextable object.Unit for returned values. One of
"in" (inches), "cm", or "mm".Return value
A named list with:widths— total table width.heights— total table height.aspect_ratio—heights / widths.
Example
See also
width()— set individual column widthsheight()— set individual row heightsset_table_properties()— set layout mode and table-level width