Autofit and format flextables

flextable_formatted(
  tab,
  autofit = TRUE,
  pg_width = 5,
  column_width = NULL,
  doc_type = "PDF",
  digits = NULL,
  font_size = 10,
  ...
)

Arguments

tab

a dataframe or flextable object. Must be coercible to a dataframe

autofit

logical (T/F). Whether or not to autofit the table.

pg_width

width (in inches) of the table. Generally 1 inch less than the default word document (8 in.)

column_width

named vector, where the column names are assigned to the desired relative width. If specified, set these column widths before fitting to word document

doc_type

Word, PDF, or HTML. Controls font size and autofit scaling.

digits

numeric. Number of digits to round to. If NULL, and as_flextable = TRUE, flextable will round to one digit.

font_size

font size of the table.

...

additional args to be passed to as_flextable() or flextable(). Which function, if any, is called depends on the type of tab. If tab is already a flextable, neither is called. If tab inherits from "grouped_data", as_flextable() is called. Otherwise flextable() is called.

Value

a formatted flextable

Details

column_width is specified using the following convention:

tab %>%
flextable_word(column_width = c("col1" = 2, "col2" = 3))

flextable by default will make the tables as wide as possible in word. This function will correct the autofit() feature and make the contents fit. Other formatting corrections are done depending on the specified doc_type