Skip to main content
Alignment and padding determine how content is positioned within each cell. flextable provides dedicated functions for horizontal alignment, vertical alignment, internal padding, line spacing, and text rotation.

Horizontal alignment

align() sets the paragraph text alignment for the selected cells:
library(flextable)

# Table of 6 columns
ft_car <- flextable(head(mtcars)[, 2:7])

# Right-align all columns in all parts
align(ft_car, align = "right", part = "all")
Accepted values: "left", "right", "center", "justify".

Aligning individual columns

Pass a vector of alignment values equal in length to the number of selected columns:
# Manually specify alignment of each column
align(
  ft_car,
  align = c("left", "right", "left", "center", "center", "right"),
  part = "all"
)

# Center-align column 2 and left-align column 5
align(ft_car, j = c(2, 5), align = c("center", "left"), part = "all")

# Alternate left and center alignment across columns 1-4 for header only
align(ft_car, j = 1:4, align = c("left", "center"), part = "header")
If the number of columns is a multiple of the length of 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:
ft <- flextable(mtcars)
ft <- align_text_col(ft, align = "left")    # left-align text columns
ft <- align_nottext_col(ft, align = "right") # right-align numeric columns
ft
Both functions accept header = TRUE (default) and footer = TRUE to propagate the alignment to those parts.
For publication tables, left-align text columns and right-align numeric columns. align_text_col() + align_nottext_col() achieve this pattern in two lines, and all built-in themes call them automatically.

Vertical alignment

valign() controls where content sits vertically inside the cell:
ft <- flextable(iris[c(1:3, 51:53, 101:103), ])
ft <- theme_box(ft)
ft <- merge_v(ft, j = 5)             # merge Species column to show spanning
ft <- valign(ft, j = 5, valign = "top", part = "all")
ft
Accepted values: "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:
ft <- flextable(head(iris))
ft <- padding(ft, padding = 8, part = "all")
Or control each side individually:
ft <- flextable(head(iris))
ft <- theme_vader(ft)
ft <- padding(ft, padding.top = 4, part = "all")
ft <- padding(ft, j = 1, padding.right = 40)   # extra right space in column 1
ft <- padding(ft, i = 3, padding.top = 40)     # extra top space in row 3
ft <- padding(ft, padding.top = 10, part = "header")
ft <- padding(ft, padding.bottom = 10, part = "header")
ft <- autofit(ft)
ft
All padding arguments are in points (pts).
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:
ft <- flextable(head(mtcars)[, 3:6])
ft <- line_spacing(ft, space = 1.6, part = "all")
ft <- set_table_properties(ft, layout = "autofit")
ft

Text rotation

rotate() changes the text direction within a cell. It supports three right-angle orientations:
ValueDirectionEffective angle
"lrtb"Left-to-right, top-to-bottom (default)
"tbrl"Top-to-bottom, right-to-left90° clockwise
"btlr"Bottom-to-top, left-to-right270° clockwise
ft <- flextable(head(iris))

# Rotate header columns 1–4 bottom-up (tbrl)
ft <- rotate(ft, j = 1:4, align = "bottom", rotation = "tbrl", part = "header")

# Rotate header column 5 top-down (btlr)
ft <- rotate(ft, j = 5, align = "bottom", rotation = "btlr", part = "header")

# Word/PowerPoint need explicit height and rule = "exact"
ft <- height(ft, height = 1.2, part = "header")
ft <- hrule(ft, i = 1, rule = "exact", part = "header")
ft
The align argument sets the vertical alignment of the rotated text within the cell: "top", "center", or "bottom".
Word and PowerPoint do not auto-size rows containing rotated text. Always set an explicit row height with height() and use hrule(rule = "exact") to prevent content from being clipped.
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

FunctionKey argumentDefault 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"