autofit: Adjusts cell widths and heights

View source: R/flextable_sizes.R

autofitR Documentation

Adjusts cell widths and heights

Description

compute and apply optimized widths and heights (minimum estimated widths and heights for each table columns and rows in inches returned by function dim_pretty()).

This function is to be used when the table widths and heights should be adjusted to fit the size of the content.

The function does not let you adjust a content that is too wide in a paginated document. It simply calculates the width of the columns so that each content has the minimum width necessary to display the content on one line.

Note that this function is not related to 'Microsoft Word' Autofit feature.

There is an alternative to fixed-width layouts that works well with HTML and Word output that can be set with set_table_properties(layout = "autofit"), see set_table_properties().

Usage

autofit(
  x,
  add_w = 0.1,
  add_h = 0.1,
  part = c("body", "header"),
  unit = "in",
  hspans = "none"
)

Arguments

x

flextable object

add_w

extra width to add in inches

add_h

extra height to add in inches

part

partname of the table (one of 'all', 'body', 'header' or 'footer')

unit

unit for add_h and add_w, one of "in", "cm", "mm".

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.

See Also

Other flextable dimensions: dim.flextable(), dim_pretty(), fit_to_width(), flextable_dim(), height(), hrule(), ncol_keys(), nrow_part(), set_table_properties(), width()

Examples

ft_1 <- flextable(head(mtcars))
ft_1
ft_2 <- autofit(ft_1)
ft_2

flextable documentation built on Oct. 30, 2024, 9:15 a.m.