fit_columns: Constrain table width by wrapping text

View source: R/flextable_sizes.R

fit_columnsR Documentation

Constrain table width by wrapping text

Description

Shrink column widths so that the total table width does not exceed max_width. Font sizes are unchanged; text wraps inside the narrower cells.

Columns that cannot shrink below their longest word (plus padding) are clamped at that floor; remaining space is iteratively redistributed among unclamped columns.

Columns listed in no_wrap keep their optimal width (as computed by dim_pretty()) and are not compressed.

To constrain width by reducing font size instead, see fit_to_width(). To size columns to their content without a width constraint, see autofit().

Usage

fit_columns(x, max_width, no_wrap = NULL, unit = "in")

Arguments

x

a 'flextable' object, see flextable-package to learn how to create 'flextable' object.

max_width

maximum total table width (in inches by default)

no_wrap

column names or indices that must keep their optimal width (no compression, no text wrapping).

unit

unit for max_width, one of "in", "cm", "mm".

See Also

Other functions for flextable size management: autofit(), dim.flextable(), dim_pretty(), fit_to_width(), flextable_dim(), height(), hrule(), ncol_keys(), nrow_part(), set_table_properties(), width()

Examples

ft <- qflextable(head(mtcars))
ft <- fit_columns(ft, max_width = 5)
flextable_dim(ft)$widths
ft

flextable documentation built on June 2, 2026, 9:08 a.m.