Tx · LaTeX & TikZ

How to Vertically Align Rotated Text in a LaTeX Table

Published By the 9to5Science editorial team

At a glance

  1. 1. Load the packages

    Use graphicx for rotation and array for vertically centered m-columns.

  2. 2. Choose a centered column

    Set the rotated-text column to m{width}; it centers its contents within the row height.

  3. 3. Rotate around the center

    Wrap the text in rotatebox with origin=c to avoid an awkward baseline shift.

  4. 4. Check the row height

    The tallest cell determines the row height, so test the result with your actual table content.

Rotated table headings can look too high or too low even when the other cells appear correctly aligned. The reliable fix is to control the table cell’s vertical alignment separately from the rotation itself.

Use an m{...} column from the array package to center the cell content vertically, and \rotatebox from graphicx to rotate the heading. Setting origin=c makes the text rotate around its center instead of its default reference point.

A complete example

\documentclass{article}
\usepackage{array}
\usepackage{graphicx}

\begin{document}

\begin{tabular}{|>{\centering\arraybackslash}m{12mm}
                |>{\raggedright\arraybackslash}m{30mm}|}
\hline
\rotatebox[origin=c]{90}{Group} & Description of the group\\
\hline
A & This description wraps onto more than one line, making the row taller.\\
\hline
B & A shorter description.\\
\hline
\end{tabular}

\end{document}

The first column has a 12 mm content width and uses m, so its contents are centered vertically within each row. The second column is also an m column; its wrapped text can make a row taller, and the rotated label is centered against that row height. \arraybackslash restores the usual meaning of \\ at the end of a cell after a declaration such as \centering or \raggedright.

The \rotatebox[origin=c]{90}{Group} command rotates the word by 90 degrees around its center. Change 90 to -90 to rotate it in the other direction. Adjust the column widths to suit your table.

What controls the alignment?

There are two separate controls:

  • Column type: In a fixed-width column, p{width} aligns cell contents at the top, m{width} centers them vertically, and b{width} aligns them at the bottom. The m and b types are provided by array.
  • Rotation origin: \rotatebox[origin=c]{angle}{text} chooses the center of the text as the point around which it rotates. Without an explicit origin, the default rotation reference can make the result appear shifted.

A row’s height is determined by its contents. If a neighboring cell contains several lines, the rotated text in an m column is centered within the resulting row. If every cell uses an ordinary c column, changing the rotation origin alone does not provide the same explicit vertical centering behavior.

For a simple table where the row heights are already suitable, you may only need the rotation command:

\rotatebox[origin=c]{90}{Heading}

Put it in the relevant cell. If it still sits too high or low relative to a taller neighboring cell, use an m{...} column for that cell.

Common mistakes

  • Using c and expecting it to center vertically. A c column centers horizontally; it is not the fixed-width, vertically centered column type. Use m{...} when vertical centering is required.
  • Changing only the rotation origin. origin=c changes the pivot for rotation, not the table column’s vertical-alignment rule. Use both controls when needed.
  • Forgetting the packages. \rotatebox requires graphicx; the m column type and \arraybackslash require array.
  • Giving the column too little width. The column still needs enough width for its cell content after rotation. Increase the m{...} width if the rotated text or nearby content looks cramped.
  • Adding manual vertical space too early. Commands such as \raisebox can fix one particular row but often need retuning when the font or content changes. Prefer column alignment first, then make a small manual adjustment only if the design specifically requires it.

If the rotated label should span several table rows, that is a separate layout problem: use a multirow cell and check its alignment across the combined row height. For a heading in one row, an m column plus \rotatebox is usually simpler.

References

  1. The LaTeX Graphics Bundle (graphicx)
  2. The array package

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.