Horizontal alignment
align() sets the paragraph text alignment for the selected cells:
"left", "right", "center", "justify".
Aligning individual columns
Pass a vector of alignment values equal in length to the number of selected columns:align, the values are recycled across the remaining columns.
Type-aware alignment helpers
align_text_col() aligns all character and factor columns; align_nottext_col() aligns all other (numeric, logical, date) columns:
header = TRUE (default) and footer = TRUE to propagate the alignment to those parts.
Vertical alignment
valign() controls where content sits vertically inside the cell:
"top", "center" (default), "bottom".
Padding
padding() sets the whitespace between the cell edge and its content, in points.
Use the padding shortcut to set all four sides:
In PDF output, only
padding.left and padding.right are supported. padding.top and padding.bottom are ignored due to LaTeX limitations. For global horizontal spacing in PDF, use set_table_properties(opts_pdf = list(tabcolsep = 1)).Line spacing
line_spacing() controls the space between lines of text within a cell. 1 is single spacing, 2 is double:
Text rotation
rotate() changes the text direction within a cell. It supports three right-angle orientations:
| Value | Direction | Effective angle |
|---|---|---|
"lrtb" | Left-to-right, top-to-bottom (default) | 0° |
"tbrl" | Top-to-bottom, right-to-left | 90° clockwise |
"btlr" | Bottom-to-top, left-to-right | 270° clockwise |
align argument sets the vertical alignment of the rotated text within the cell: "top", "center", or "bottom".
When
autofit() is used, rotation is ignored. Use dim_pretty() and width() instead when working with rotated headers.Best practices for publication tables
Text columns
Left-align character and factor columns in body and header. Use
align_text_col() as a shortcut.Numeric columns
Right-align numbers so decimal points line up vertically. Use
align_nottext_col() as a shortcut.Padding
Consistent padding (4–6 pts on all sides) improves readability. Apply globally with
padding(ft, padding = 5, part = "all").Rotated headers
Rotate only when column headers are substantially longer than the cell values. Always set explicit row heights for Word/PowerPoint output.
Quick reference
| Function | Key argument | Default part |
|---|---|---|
align(x, i, j, align, part) | align — "left", "right", "center", "justify" | "body" |
align_text_col(x, align, header) | align = "left" | — |
align_nottext_col(x, align, header) | align = "right" | — |
valign(x, i, j, valign, part) | valign = "center" | "body" |
padding(x, i, j, padding, ..., part) | padding — uniform pts or individual sides | "body" |
line_spacing(x, i, j, space, part) | space = 1 | "body" |
rotate(x, i, j, rotation, align, part) | rotation — "lrtb", "tbrl", "btlr" | "body" |