How to rotate the large table and caption?

I want to rotate a large table with the caption. However, I can not rotate the caption for the table. Do you have any ideas how to rotate the caption for this layout? Thanks a lot.

Here my text code is below

\rotatebox{90}{
% \caption{Comparison} I cannot use this function like that
\begin{tabular}{l*{6}{c}r}
\hline
Names  & A & B & C & D \\
\hline
\hline
Jobs   & A & B & C & D \\
\hline
Types   & A & B & C & D \\
\hline
\end{tabular}
}

• Real quick: Why did you set the tags biblatex and table-of-contents? – Mico May 18 '17 at 14:33
• You can not use the standard \caption-command outside of floats (figure or table). – Skillmon May 18 '17 at 14:37
• OK, thanks a lot for your comment. I will remove the tags as you suggested. – user3727281 May 18 '17 at 14:49

I tried this:

\documentclass{article}
\usepackage{rotating}

\begin{document}

\begin{sidewaystable}
\centering
\caption{Comparison}
\begin{tabular}{l*{6}{c}r}
\hline
Names  & A & B & C & D \\
\hline
\hline
Jobs   & A & B & C & D \\
\hline
Types   & A & B & C & D \\
\hline
\end{tabular}

\end{sidewaystable}

\end{document}


While iacopo's answer is the way I'd choose, here is a different solution:

\documentclass[]{scrartcl}

\usepackage{rotating}

\begin{document}

\rotatebox{90}{
\vbox{
\centering
\captionaboveof{table}{Comparison}
\begin{tabular}{l*{6}{c}r}
\hline
Names  & A & B & C & D \\
\hline
\hline
Jobs   & A & B & C & D \\
\hline
Types   & A & B & C & D \\
\hline
\end{tabular}
}
}
\end{document}


If you don't use a KOMA-class you can use the package caption and replace \captionaboveof with \captionof.

As an alternative option to the previous two, for really large tables I prefer to rotate the whole page instead:

\documentclass{article}

\usepackage{pdflscape}
\usepackage{afterpage}

\begin{document}

\afterpage{%
\clearpage% Flush earlier floats (otherwise order might not be correct)
\begin{landscape}% Landscape page
\begin{table}
\centering
\caption{Comparison}
\begin{tabular}{l*{6}{c}r}
\hline
Names  & A & B & C & D \\
\hline
\hline
Jobs   & A & B & C & D \\
\hline
Types   & A & B & C & D \\
\hline
\end{tabular}
\end{table}
\end{landscape}
\clearpage% Flush page
}
\end{document}


This has the advantage that the page displays correctly in software and prints like normal with headers and footers in normal orientation. It really depends on your requirements.

(credit to Martin Scharrer for this answer)