% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/flextable_sizes.R
\name{fit_columns}
\alias{fit_columns}
\title{Constrain table width by wrapping text}
\usage{
fit_columns(x, max_width, no_wrap = NULL, unit = "in")
}
\arguments{
\item{x}{a 'flextable' object, see \link{flextable-package} to learn how to create
'flextable' object.}

\item{max_width}{maximum total table width (in inches by default)}

\item{no_wrap}{column names or indices that must keep their
optimal width (no compression, no text wrapping).}

\item{unit}{unit for \code{max_width}, one of "in", "cm", "mm".}
}
\description{
Shrink column widths so that the total table width
does not exceed \code{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 \code{no_wrap} keep their optimal width (as computed
by \code{\link[=dim_pretty]{dim_pretty()}}) and are not compressed.

To constrain width by reducing font size instead, see
\code{\link[=fit_to_width]{fit_to_width()}}. To size columns to their content without a
width constraint, see \code{\link[=autofit]{autofit()}}.
}
\examples{
ft <- qflextable(head(mtcars))
ft <- fit_columns(ft, max_width = 5)
flextable_dim(ft)$widths
ft
}
\seealso{
Other functions for flextable size management:
\code{\link[=autofit]{autofit()}},
\code{\link[=dim.flextable]{dim.flextable()}},
\code{\link[=dim_pretty]{dim_pretty()}},
\code{\link[=fit_to_width]{fit_to_width()}},
\code{\link[=flextable_dim]{flextable_dim()}},
\code{\link[=height]{height()}},
\code{\link[=hrule]{hrule()}},
\code{\link[=ncol_keys]{ncol_keys()}},
\code{\link[=nrow_part]{nrow_part()}},
\code{\link[=set_table_properties]{set_table_properties()}},
\code{\link[=width]{width()}}
}
\concept{functions for flextable size management}
