1

I want to rotate a table because it is too wide. I'm forced to use \documentclass[11pt,a4paper]{article}, so changing that is not a solution. Many packages rotate the whole page, but I just wan't to rotate the table.

I have a design sample of a table, that I must use. In my tex code that is my first table. enter image description here

The second snippet is how I can rotate a table. Yet I'm missing a required caption on the table. enter image description here

The third snippet is what I actually want, but I'm getting a LaTeX Error: Not in outer par mode . I found a similar question Rotate table with caption: "Not in outer par mode. \begin{table}[h]" but the answer provided a solution with sidewaystable and that is just plain ugly in my case, because then the rotated table occupies a whole page on its own.

\documentclass[11pt,a4paper]{article}
\usepackage[graphicx]{realboxes}
\usepackage{verbatim}
\begin{document}
\begin{table}[htb]
\begin{center}
\begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
\hline
\bf Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
\hline \hline
first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\
\hline
\end{tabular}
\end{center}
 \caption{My caption lorem ipsum}\label{tab_aaa}
\end{table}


%rotated
\rotatebox{90}{
\begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
\hline
\bf Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
\hline \hline
first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\
\hline
\end{tabular}
}

\begin{comment}
%% what i want
\rotatebox{90}{
\begin{table}[htb]
\begin{center}
\begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
\hline
\bf Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
\hline \hline
first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\
\hline
\end{tabular}
\end{center}
 \caption{My caption lorem ipsum}\label{tab_b}
\end{table}
}
\end{comment}
\end{document}

How can I add a caption to the second snippet?

3 Answers 3

3

You table is quite large and will imho take up a page anyway, so sidewaystable is probably the best solution. But you can also put the tabular and the caption in a minipage or a varwidth box and rotate this:

\documentclass[11pt,a4paper]{article}
\usepackage[graphicx]{realboxes}
\usepackage{varwidth}
\begin{document}
%% what i want
\begin{table}[htb]
\centering
 \rotatebox{90}{%
   \begin{varwidth}{\textheight}
      \begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
       \hline
        \bfseries Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
         \hline \hline
        first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\            \hline
       \end{tabular}
        \caption{My caption lorem ipsum}\label{tab_b}
    \end{varwidth}}
\end{table}


For the table see \ref{tab_b}

\end{document}

N.B: Don't use \bf, use \bfseries instead.

1
  • Thank you. I solved a not in outer par modeproblem I had with a tabular inside a rotatebox with your code example. The varwidth environment helped. Jun 15, 2016 at 17:22
1
\documentclass[11pt,a4paper]{article}
\usepackage{hvfloat}
\def\RB#1{\rotatebox{90}{#1}}
\begin{document}

\hvFloat[%
     floatPos=!htb,
     capWidth=h,% of \columnwidth
     capPos=r,
     objectAngle=90,
     capAngle=90,
     objectPos=l % l c r
]{table}{%
\begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}\hline
\bf Some text & \RB{column 1  } &  \RB{column 2} & \RB{column 3  } & \RB{column 4 } & \RB{column 5 }  & \RB{column 6  } &  \RB{column 7} & \RB{column 8 } & \RB{column 9 } & \RB{column 10 } & \RB{column 11 } &  \RB{column 12} & \RB{column 13 } & \RB{column 14  } & \RB{column 15 }\\
\hline \hline
first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\
\hline
\end{tabular}
}%
[Centered Caption beside Object] % TOC entry
{Caption vertically centered right beside the float with a caption
           width of \texttt{0.5\textbackslash columnwidth} and \texttt{%
           floatcapsep=5pt} (the default)}
{fig:2}% label

\end{document}
0

I found that is easiest to use the roatfloat package. This also serves with sidewaystable although not for this example.

    \documentclass[11pt,a4paper]{article}
    \usepackage{rotfloat}
    \usepackage{varwidth}

    \begin{document}
       For the table see \ref{tab_a}
        \begin{table}[H]
             \centering
             \rotatebox{90}{%
                \begin{varwidth}{\textheight}
                  \begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
                  \hline
                  \bfseries Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
                  \hline \hline
                  first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\            \hline
                  \end{tabular}
                \caption{My caption lorem ipsum}\label{tab_a}
               \end{varwidth}}
        \end{table}

     Another reference see \ref{tab_a}
   \end{document}

You must log in to answer this question.

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