Function converts a gtsummary object to a flextable object. A user can use this function if they wish to add customized formatting available via the flextable functions. The flextable output is particularly useful when combined with R markdown with Word output, since the gt package does not support Word.

  include = everything(),
  return_calls = FALSE,
  strip_md_bold = TRUE



Object created by a function from the gtsummary package (e.g. tbl_summary or tbl_regression)


Commands to include in output. Input may be a vector of quoted or unquoted names. tidyselect and gtsummary select helper functions are also accepted. Default is everything().


Logical. Default is FALSE. If TRUE, the calls are returned as a list of expressions.


When TRUE, all double asterisk (markdown language for bold weight) in column labels and spanning headers are removed.


A flextable object


The as_flex_table() functions converts the gtsummary object to a flextable, and prints it with the following styling functions.

  1. flextable::flextable()

  2. flextable::set_header_labels() to set column labels

  3. flextable::add_header_row(), if applicable, to set spanning column header

  4. flextable::align() to set column alignment

  5. flextable::padding() to indent variable levels

  6. flextable::fontsize() to set font size

  7. flextable::autofit() to estimate the column widths

  8. flextable::footnote() to add table footnotes and source notes

  9. flextable::bold() to bold cells in data frame

  10. flextable::italic() to italicize cells in data frame

  11. flextable::border() to set all border widths to 1

  12. flextable::padding() to set consistent header padding

  13. flextable::valign() to ensure label column is top-left justified

Any one of these commands may be omitted using the include= argument.

Pro tip: Use the flextable::width() function for exacting control over column width after calling as_flex_table().

Example Output

Example 1

See also

Other gtsummary output types: as_gt(), as_hux_table(), as_kable_extra(), as_kable(), as_tibble.gtsummary()


Daniel D. Sjoberg


as_flex_table_ex1 <-
  trial %>%
  select(trt, age, grade) %>%
  tbl_summary(by = trt) %>%
  add_p() %>%