171

I have a table and I want to rotate it. The table has 3 rows and 4 columns, and I want to rotate the text inside this table as well. How can I do this?

2
  • 26
    please, for the love of god, don't use sidewaystables unless you intend the document to be read while lying down. There's nothing more annoying than having to crane your neck to read a table in a pdf, use lscape or pdflscape so the table is rotated properly when shown on a monitor.
    – Shep
    Commented Sep 10, 2014 at 1:45
  • 4
    In relation to previous comment: see this answer for rotating a floating table with pdflscape
    – Olivier
    Commented Sep 22, 2015 at 8:19

6 Answers 6

58

As Jake said you can use \rotatebox from the graphicx package to rotate a table. This is perfectly fine for uncomplicated tables. However, this will read the whole table as macro argument which doesn't allow for verbatim or other special content and isn't that efficient.

As alternative you can use the \adjustbox macro or adjustbox environment from the adjustbox package (written by me). Both process the content as real box and not as macro argument as therefore avoids the mentioned drawbacks:

\documentclass{article}
\usepackage{adjustbox}

\begin{document}

\begin{adjustbox}{angle=90}
    \begin{tabular}{ll}
    First First & First Second\\
    Second First & Second Second
    \end{tabular}
\end{adjustbox}
\end{document}

Alternatively, you can use the very new package realboxes. When loaded with the graphicx option (or without any but after graphicx) it provides \Rotatebox which works like \rotatebox but reads the content also as real box:

\documentclass{article}
\usepackage[graphicx]{realboxes}

\begin{document}

\Rotatebox{90}{%
    \begin{tabular}{ll}
    First First & First Second\\
    Second First & Second Second
    \end{tabular}
}%
\end{document}
5
  • 3
    I am not able to get a caption on my table. How can I do that
    – Agaz Wani
    Commented Jul 8, 2018 at 11:42
  • 2
    @AaghazHussain: You can't place floats (table, figure etc.) inside boxes. You need to either place the table environment around the rotated box while placing the \caption inside it OR use a non-floating alternative like \captionof (see (Label and caption without float)[tex.stackexchange.com/q/7210/2975]) or the caption={the caption text},nofloat=table keys when you useadjustbox. Commented Jul 9, 2018 at 14:03
  • 1
    Thanks, I got the caption but not rotated with the table and also I try to center the rotated table \begin{adjustbox}{width=\textwidth,totalheight=\textheight,keepaspectratio,rotate=90,caption={Time taken in seconds}, float=table, center}, but it is not centering.
    – Agaz Wani
    Commented Jul 10, 2018 at 11:15
  • 1
    @AaghazHussain: The order of keys is important. You can't center a float, you need to center the content of it. Do you really need a floating table here? Because if not, simply change float= to nonfloat= and move the rotate key just before the center key. It looks to me that you want it over the full page size right? Then you might want to wrap the whole thing into an \afterpage{..} (afterpage package) to place it on the next page. Maybe with \clearpage added before the adjustbox. Also you should check you width and height, as they are the dimensions BEFORE the rotate! Commented Jul 10, 2018 at 12:12
  • @AaghazHussain: If you still have issues don't hesitate to add a new question for your specific problem. Please add a link to this answer and state what is still missing and what you want to achieve exactly. Commented Jul 10, 2018 at 12:13
165

Another option is to use sidewaystable from the rotating package.

\documentclass{article}
\usepackage{rotating}

\begin{document}

\begin{sidewaystable}
    \centering
    \caption{Your caption here}
   \begin{tabular}{ll}
    First First & First Second\\
    Second First & Second Second
    \end{tabular}
\end{sidewaystable}

\end{document}
4
  • 5
    How can one change the direction of table using this method?
    – Academic
    Commented May 24, 2021 at 11:34
  • 2
    @Aymuos check on this interesting discussion: tex.stackexchange.com/a/522866/208021 Maybe this helps you understanding how the sidewaystable package works.
    – revy
    Commented Nov 21, 2021 at 15:51
  • 1
    sidewaystable automatically adjusts the direction of rotation for even and odd pages. Commented Apr 6, 2022 at 17:07
  • 1
    This didn't work!
    – bonCodigo
    Commented Feb 15, 2023 at 4:40
77

If all you want to do is rotate the complete table, but keep everything else on the page unrotated, you can use the \rotatebox{<angle>}{ ... } command from the graphicx package:

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\rotatebox{90}{
    \begin{tabular}{ll}
    First First & First Second\\
    Second First & Second Second
    \end{tabular}
}
\end{document}

However, if you have a large table that will take up the whole page, you might want to rotate the page instead of the table. You can do this using the pdflscape package if you're compiling with pdflatex, or lscape if you're using latex, which introduce a landscape environment.

\documentclass{article}
\usepackage{pdflscape}

\begin{document}
\begin{landscape}
    \begin{tabular}{ll}
    First First & First Second\\
    Second First & Second Second
    \end{tabular}
\end{landscape}
\end{document}
2
  • 10
    the landscape option is the best option: there's nothing more obnoxious than inserting a sideways table and forcing your reader to crane his neck just to read the pdf.
    – Shep
    Commented Sep 10, 2014 at 1:42
  • 1
    It is a nice option indeed. However in my document the page number is still in portrait mode, which makes it at the side of the page instead of at the bottom. Also, it doesn't disappear, no matter if I put a \thispagestyle{empty} before or after the \begin{landscape}. How to fix that?
    – Andyc
    Commented Mar 3, 2020 at 2:39
19

Assuming you want to rotate the table because it doesn't fit the width of a portrait page. Based on @Shep's comment to this question: use the pdflscape package (CTAN, dtx, pdf) by Heiko Oberdiek.

Package pdflscape adds PDF support to the environment landscape of package lscape by setting the PDF page attribute /Rotate

I use Lyx, and it's in the FAQ: How can I typeset certain pages of my documents in landscape mode?

Use the package lscape (or better pdflscape, which also supports pdflatex output). Add to the preamble: \usepackage{pdflscape} In the document, embrace the pages which should be in landscape mode by:

\begin{landscape}
...
\end{landscape}

All other text will be in portrait mode pages. If you don't have the pdflscape package installed, get it from ctan The lscape package is part of the graphics bundle and should be installed by default.

2
  • Are you able to help with this question here about rotating a large table in Lyx?
    – hhh
    Commented Mar 13, 2016 at 21:10
  • 1
    Even though I really like this solution, some printing services (such as bod) have issues with rotated pages. A check with your printing service is needed before using landscape.
    – koppor
    Commented Jul 12, 2016 at 20:06
8

The ctable packages also has an option to rotate the table: sideways. For example:

\documentclass{article}
\usepackage{ctable}

\begin{document}
\ctable[
caption={Your table caption},
label={tab:mytable},
botcap, % caption below table
sideways % This rotates the table
]
{ccc}
{
% Table footnotes here, see ctable docs
}
{
Column 1 & Column 2 & Column 3 \\
Row 2, 1 & 2, 2     & 2, 3 \\
}
\end{document}
0
2

This is very old post, but there is one more way to rotate a table is putting it inside a TikZ's handy node. The advantage is that you can use all options of node. For example:

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}     % >>> for dummy text only
\begin{document}
\lipsum[1]  
\begin{center}
\begin{tikzpicture}
\node[rotate=90,transform shape,fill=yellow!30,inner sep=]{
\begin{tabular}{|c|c|}
\hline
First First & First Second\\
\hline
Second First & Second Second\\
\hline
\end{tabular}
};      
\end{tikzpicture}
\end{center}
\lipsum[2]
\end{document}

From pgfmanual

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .