Skip to main content

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.

rotate() changes the text direction of selected cells. It supports 90-degree rotation increments and is particularly useful for compact column headers.

Function signature

rotate(x, i = NULL, j = NULL, rotation, align = NULL, part = "body")

Parameters

x
flextable
required
A flextable object.
i
integer | formula | logical
Row selector. NULL selects all rows in the specified part.
j
integer | character | formula
Column selector. NULL selects all columns.
rotation
string
required
Text direction. One of:
  • "lrtb" — left to right, top to bottom (standard horizontal, the default in most output formats).
  • "tbrl" — top to bottom, right to left (vertical, rotated 90° clockwise — text reads downward).
  • "btlr" — bottom to top, left to right (vertical, rotated 270° clockwise — text reads upward).
align
string
Vertical alignment of the paragraph within the cell after rotation. One of "top", "center", or "bottom". NULL leaves the current alignment unchanged.
part
string
default:"\"body\""
Which part of the table to target: "body", "header", "footer", or "all".

Return value

The modified flextable object.

Examples

Rotate header labels to save horizontal space:
library(flextable)

ft <- flextable(head(iris))
ft <- rotate(ft, j = 1:4, align = "bottom", rotation = "tbrl", part = "header")
ft <- rotate(ft, j = 5, align = "bottom", rotation = "btlr", part = "header")

# Word and PowerPoint require explicit height and exact rule for rotated headers
ft <- height(ft, height = 1.2, part = "header")
ft <- hrule(ft, i = 1, rule = "exact", part = "header")
ft
Combine rotation with horizontal and vertical alignment:
dat <- data.frame(
  a = c("left-top", "left-middle", "left-bottom"),
  b = c("center-top", "center-middle", "center-bottom"),
  c = c("right-top", "right-middle", "right-bottom")
)

ft <- flextable(dat)
ft <- theme_box(ft)
ft <- height_all(x = ft, height = 1.3, part = "body")
ft <- hrule(ft, rule = "exact")
ft <- rotate(ft, rotation = "tbrl")
ft <- width(ft, width = 1.3)

ft <- align(ft, j = 1, align = "left")
ft <- align(ft, j = 2, align = "center")
ft <- align(ft, j = 3, align = "right")

ft <- valign(ft, i = 1, valign = "top")
ft <- valign(ft, i = 2, valign = "center")
ft <- valign(ft, i = 3, valign = "bottom")
ft
Word and PowerPoint do not handle automatic row height for rotated content. You must explicitly set row heights with height() and set the height rule to "exact" with hrule(), otherwise the text will be clipped.Rotation is also ignored when autofit() calculates column widths. Use dim_pretty() and width() manually instead.
flextable only supports rotation in 90-degree increments ("lrtb", "tbrl", "btlr") to ensure consistent rendering across Word, PowerPoint (which supports only 0°, 90°, and 270°), HTML, and PDF.

See also

  • valign() — set vertical alignment
  • align() — set horizontal text alignment
  • height() — set row height
  • hrule() — control how row heights are interpreted
  • dim_pretty() — compute optimal sizes without applying them

Build docs developers (and LLMs) love