Print openxml, latex or html code of a flextable. The function is particularly useful when you want to generate flextable in a loop from a R Markdown document.

Inside R Markdown document, chunk option results must be set to 'asis'.

All arguments whose name starts with ft. can be set in the chunk options.

See knit_print.flextable for more details.

  ft.align = opts_current$get("ft.align"),
  ft.split = opts_current$get("ft.split"),
  ft.keepnext = opts_current$get("ft.keepnext"),
  ft.tabcolsep = opts_current$get("ft.tabcolsep"),
  ft.arraystretch = opts_current$get("ft.arraystretch"),
  ft.latex.float = mcoalesce_options(opts_current$get("ft.latex.float"),
  ft.left = opts_current$get("ft.left"), = opts_current$get(""),
  text_after = "",
  webshot = opts_current$get("webshot"),
  ft.htmlscroll = opts_current$get("ft.htmlscroll"),
  ft.shadow = opts_current$get("ft.shadow"),
  bookdown = FALSE,
  quarto = FALSE,
  pandoc2 = TRUE,
  print = TRUE,



a flextable object


flextable alignment, supported values are 'left', 'center' and 'right'.


Word option 'Allow row to break across pages' can be activated when TRUE.


default FALSE. Word option 'keep rows together' is activated when TRUE. It avoids page break within tables. This is handy for small tables, i.e. less than a page height.

Be careful, if you print long tables, you should rather set its value to FALSE to avoid that the tables also generate a page break before being placed in the Word document. Since Word will try to keep it with the next paragraphs that follow the tables.


space between the text and the left/right border of its containing cell, the default value is 0 points.


height of each row relative to its default height, the default value is 1.5.


type of floating placement in the document, one of:

  • 'none' (the default value), table is placed after the preceding paragraph.

  • 'float', table can float to a place in the text where it fits best

  • 'wrap-r', wrap text around the table positioned to the right side of the text

  • 'wrap-l', wrap text around the table positioned to the left side of the text

  • 'wrap-i', wrap text around the table positioned inside edge-near the binding

  • 'wrap-o', wrap text around the table positioned outside edge-far from the binding


Position should be defined with options ft.left and Theses are the top left coordinates in inches of the placeholder that will contain the table. Their default values are 1 and 2 inches.


The string you put here will be added after printing the content of the flextable. For example, you can put "\\pagebreak" here to have tables produced with page breaks.


webshot package as a scalar character, one of "webshot" or "webshot2".


TRUE or FALSE (default) to enable horizontal scrolling.


TRUE (default) or FALSE to use shadow dom (for HTML only), this option is existing to disable shadow dom (set to FALSE) for pagedown and Quarto that can not support it for now.


TRUE or FALSE (default) to support cross referencing with bookdown.


TRUE or FALSE (default) to indicate the source document is a 'Quarto' file (ending with *.qmd).


TRUE (default) or FALSE to get the string in a pandoc raw HTML attribute (only valid when pandoc version is >= 2.


print output if TRUE


unused arguments


demo_loop <- system.file(package = "flextable", "examples/rmd", "loop_with_flextable.Rmd")
rmd_file <- tempfile(fileext = ".Rmd")
file.copy(demo_loop, to = rmd_file, overwrite = TRUE)
#> [1] TRUE
rmd_file # R Markdown document used for demo
#> [1] "/tmp/Rtmp8v4LMn/file318d3c3d3655.Rmd"
if (require("rmarkdown", quietly = TRUE)) {
  #  render(input = rmd_file, output_format = "word_document",
  #    output_file = "loop_with_flextable.docx")
  #  render(input = rmd_file, output_format = "html_document",
  #    output_file = "loop_with_flextable.html")
  #  render(input = rmd_file,
  #    output_format = rmarkdown::pdf_document(latex_engine = "xelatex"),
  #    output_file = "loop_with_flextable.pdf")