Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment
\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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.