I'm creating a table like this:
\captionof{table}{caption}
\begin{tabular}{@{} *5l @{}}\toprule
\emph{header1} & \emph{header2} & \emph{header3} \\\midrule
item1 & v1 & v2 \\
item2 & v1 & v2 \\
item2 & v1 & v2 \\
\hline
\label{table:label}
\end{tabular}
This way the caption gets separated from the table and if it reaches the end of the page the table might go to the next page while its caption remains on the previous page. If I move the caption inside tabular I get an error:
You can't use `\hrule' here except with leaders.
\caption@hrule ->\hrule
and if I use \caption instead:
Package caption Error: \caption outside float
I've added these lines to use caption for my tables:
\usepackage[hypcap]{caption}
\captionsetup[table]{name=table}
Best Answer
Have you considered using the
booktabs
package?This is your example a little re-arranged: