Skip to contents

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".

Examples

ft <- qflextable(head(mtcars))
ft <- fit_columns(ft, max_width = 5)
#> Warning: Column floor widths exceed max_width; some text wrapping at word boundaries may not be achievable.
flextable_dim(ft)$widths
#> [1] 5.516461
ft

mpg

cyl

disp

hp

drat

wt

qsec

vs

am

gear

carb

21.0

6

160

110

3.90

2.620

16.46

0

1

4

4

21.0

6

160

110

3.90

2.875

17.02

0

1

4

4

22.8

4

108

93

3.85

2.320

18.61

1

1

4

1

21.4

6

258

110

3.08

3.215

19.44

1

0

3

1

18.7

8

360

175

3.15

3.440

17.02

0

0

3

2

18.1

6

225

105

2.76

3.460

20.22

1

0

3

1