# How to “glue” the caption to the table (stay on the same page as the table)

Normally, my captions stay with the table
(cannot remember my exact example - couldn't replicate it - but I am now using the booktabs package anyway so let us take this one just in case this one is easy to solve...)

Can you see any reason here why the caption may not be "glued" to the table?
I want the caption to definitely stay on the same page (and in this case above the table)

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{booktabs}
\usepackage{array}
\usepackage{dcolumn}
\begin{document}
\begin{table}
\caption{Investment overview}\label{tab:Invest}
\centering
\begin{tabular}{@{\raggedright}p{4.5cm}@{\kern-30pt}*{6}{>{\small}r}@{}}\toprule
\textit{Alternative 1}  &  Time of     & Year\\[-2pt]
&  investment  & 2006 & 2007 & 2008 & 2008 & 2010 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}

-
When you say you "couldn't replicate it", does that mean you could not replicate any example where the described behaviour appears? In that case, it will be very difficult to help, I think. Also, with problems like this it's really important to add what documentclass you are using (that line is missing in your example). – Jake Mar 23 '11 at 16:28
Might be an idea to also include the class. As it stands here any normal class would not break this across a page break. BTW: why do you use \hline as well? replace it with \bottomrule. You the following might also be useful \usepackage[tablelocation=top]{caption} (or something like that) – daleif Mar 23 '11 at 16:30
@daleif @Jake just added \documentclass[a4paper,10pt]{scrartcl} – user3992 Mar 23 '11 at 16:37
@daleif now using \bottomrule instead of \hline - thanks – user3992 Mar 23 '11 at 16:39

In the shown example the caption will always be on the same page as the table (tabular) because they are inside a table float which doesn't allow page breaks.
• You do not place them into a table float, e.g. because you want to place them at a specific position and do not want them to float. In this case (actually all cases) it is a good idea to not have an empty line between \caption and \begin{tabular} because this adds a paragraph between both! Also you can place both then into a box, e.g. inside a minipage environment which will glue them together so that they are not split across pages.
• You are using a special style for table, like the ones provided by the float package. Then the caption will be placed at the position defined by the style, not by your code. However, the caption would still be always at the same page as the content.
BTW: The use of the booktabs package should not have any influence on this. – Martin Scharrer Mar 23 '11 at 16:30
> a good idea to not have an empty line between \caption and \begin{tabular} -- do I need to move \centering then or just close the line gap? – user3992 Mar 23 '11 at 16:43
@Alex: \centering should come directly after \begin{tabular}. Also do not have empty lines around it as well. You can add lines with only % as visual separations if you like. The % makes LaTeX ignore them. – Martin Scharrer Mar 23 '11 at 17:52
> @Alex: \centering should come directly after \begin{tabular}. - Seems to us it should come before \begin{tabular} i.e. after \begin{table} – user3992 Mar 25 '11 at 6:25