When knitting to PDF,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/davidgohel/flextable/llms.txt
Use this file to discover all available pages before exploring further.
knit_print.flextable() automatically generates LaTeX code. No setup is required beyond a working LaTeX installation.
LaTeX engine requirements
The defaultpdflatex engine does not support custom font families. If your tables use system fonts (set via set_flextable_defaults(font.family = ...)), you must switch to xelatex or lualatex.
Set the engine in the YAML header of your R Markdown or Quarto document:
- R Markdown
- Quarto
pdflatex by setting:
Required LaTeX packages
flextable automatically loads the following LaTeX packages via knitr metadata:fontspec(xelatex/lualatex only)multirow,multicolcolortblulemhhlinelongtablearrayhyperref
Adding dependencies manually with add_latex_dep()
When chunk caching is enabled, knitr uses the cached output and skips the chunk that would normally register LaTeX dependencies. Call add_latex_dep() in a non-cached chunk to ensure the dependencies are included:
Chunk options for PDF
Control LaTeX rendering per-chunk or globally:| Chunk option | Description | Default |
|---|---|---|
ft.tabcolsep | Space (pt) between text and left/right cell border | 0 |
ft.arraystretch | Row height multiplier | 1.5 |
ft.latex.float | Float container type | "none" |
set_table_properties():
Float behavior
Theft.latex.float chunk option (or set_table_properties(float = ...)) controls how the LaTeX table is wrapped:
| Value | Container | Description |
|---|---|---|
"none" | No container | Table appears inline at its location |
"float" | float package | Table floats to optimal position |
"wrap-r" | wrapfig package | Text wraps around right side |
"wrap-l" | wrapfig package | Text wraps around left side |
"wrap-i" | wrapfig package | Inner margin (for two-column) |
"wrap-o" | wrapfig package | Outer margin (for two-column) |
PDF limitations
The following formatting properties have no effect in PDF output:padding.topandpadding.bottomline_spacing- Row
height - Justified text alignment (converted to left-aligned)
- Images inside table cells
- Equations (
as_equation()) and hyperlinks
Font families
Withxelatex or lualatex, flextable loads the fontspec package and applies font families defined on text runs. The font must be installed on your system.
To use the Liberation Sans font (included with the gdtools package):
pdflatex, fall back to LaTeX default fonts: