[Tex/LaTex] How to “glue” the caption to the table (stay on the same page as the table)

captionspage-breakingtables

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}

Best Answer

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.

Possibilities why the caption could move:

  • 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.