Rotate a table in LaTeX (sidewaystable, landscape, rotatebox)

The sidewaystable environment from the rotating package turns a table with its caption by 90 degrees and puts it on a page of its own. \rotatebox from graphicx rotates a tabular or a single cell.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{rotating}
\usepackage{booktabs}

Rotate a table with its caption

Replace table with sidewaystable. The environment is a float like table, with \caption and \label, and the available width inside is the height of the text block.

\begin{sidewaystable}
\centering
\caption{Monthly rainfall in millimeters}
\begin{tabular}{lrrrrrrrrrrrr}
\toprule
City   & Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec \\
\midrule
Bergen & 190 & 152 & 170 & 114 & 106 & 132 & 148 & 190 & 283 & 271 & 259 & 235 \\
Madrid & 33  & 35  & 25  & 45  & 51  & 21  & 12  & 10  & 22  & 60  & 58  & 51 \\
\bottomrule
\end{tabular}
\end{sidewaystable}
Result
The compiled example

Open in the editor

Turn whole pages to landscape

The landscape environment from pdflscape starts a new page and rotates everything inside it, also a longtable that runs over several pages. Header and page number stay where they are on portrait pages. The PDF viewer shows these pages turned, so the table is readable on screen.

Complete document:

\documentclass{article}
\usepackage{pdflscape}
\usepackage{booktabs}
\begin{document}
Text on a portrait page.

\begin{landscape}
\begin{table}
\centering
\caption{Monthly rainfall in millimeters}
\begin{tabular}{lrrrrrr}
\toprule
City   & Jan & Feb & Mar & Apr & May & Jun \\
\midrule
Bergen & 190 & 152 & 170 & 114 & 106 & 132 \\
\bottomrule
\end{tabular}
\end{table}
\end{landscape}
\end{document}
Result
Page 1 of the compiled examplePage 1
Page 2 of the compiled examplePage 2

Open in the editor

Rotate only the tabular

\rotatebox{90}{...} turns its content by 90 degrees counterclockwise. The caption outside the box stays horizontal, and the table stays on a normal page between the text.

\begin{table}
\centering
\rotatebox{90}{%
\begin{tabular}{lr}
\toprule
Item   & Price \\
\midrule
Apple  & 0.50 \\
Banana & 0.25 \\
\bottomrule
\end{tabular}}
\caption{Fruit prices}
\end{table}
Result
The compiled example

Open in the editor

Rotate the column headers

Long headers above narrow columns take less width when each header cell is rotated. The angle is free; 90 gives vertical text.

\begin{tabular}{lccc}
\toprule
Name & \rotatebox{90}{Attendance} & \rotatebox{90}{Homework} & \rotatebox{90}{Final exam} \\
\midrule
Anna & yes & yes & no \\
Ben  & yes & no  & yes \\
\bottomrule
\end{tabular}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages