% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/flextable_sizes.R
\name{autofit}
\alias{autofit}
\title{Adjust columns to their content size}
\usage{
autofit(
  x,
  add_w = 0.1,
  add_h = 0.1,
  part = c("body", "header"),
  unit = "in",
  hspans = "none"
)
}
\arguments{
\item{x}{a 'flextable' object, see \link{flextable-package} to learn how to create
'flextable' object.}

\item{add_w}{extra width to add in inches}

\item{add_h}{extra height to add in inches}

\item{part}{part selector, see section \emph{Part selection with the \code{part}
parameter} in <\code{\link[=flextable_selectors]{Selectors in flextable}}>.
Value 'all' can be used.}

\item{unit}{unit for add_h and add_w, one of "in", "cm", "mm".}

\item{hspans}{specifies how cells that are horizontally are included in the calculation.
It must be one of the following values "none", "divided" or "included". If
"none", widths of horizontally spanned cells is set to 0 (then do not affect the
widths); if "divided", widths of horizontally spanned cells is divided by
the number of spanned cells; if "included", all widths (included horizontally
spanned cells) will be used in the calculation.}
}
\description{
Compute and apply the minimum widths and heights needed
to display each cell's content on a single line, with an optional
extra margin (\code{add_w}, \code{add_h}).

This function sizes columns to fit their content. It does not
constrain the table to a given total width. To enforce a maximum
width, use \code{\link[=fit_columns]{fit_columns()}} (wraps text) or \code{\link[=fit_to_width]{fit_to_width()}}
(shrinks font size).

Note that this function is not related to 'Microsoft Word'
\emph{Autofit} feature.

There is an alternative to fixed-width layouts that works
well with HTML and Word output that can be set
with \code{set_table_properties(layout = "autofit")}, see
\code{\link[=set_table_properties]{set_table_properties()}}.
}
\examples{
ft_1 <- flextable(head(mtcars))
ft_1
ft_2 <- autofit(ft_1)
ft_2
}
\seealso{
Other functions for flextable size management:
\code{\link[=dim.flextable]{dim.flextable()}},
\code{\link[=dim_pretty]{dim_pretty()}},
\code{\link[=fit_columns]{fit_columns()}},
\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}
