# How to control table and its title to appear on the same page

Problem: Table's title appears on a different page, and it looks really bad.

The next mage shows what I need to fix:

("Cuadro 4.2" means "Table 4.2" in English. That is the title added by captionof.)

The code I am using for tables looks like this:

\begin{center}
\captionof{table}{Convergencia pm6-cluster}\label{table:convergencia_cluster_pm6}
\begin{tabular}{|l|l|l|}
\hline
\textbf{nºconf} & \textbf{$\Delta G^0$-SS} & \textbf{$\Delta G^0$-Packmol} \\ \hline
5 & -64.6 & -64.7 \\ \hline
10 & -65.5 & -64.1 \\ \hline
15 & -63.7 & -66.5 \\ \hline
20 & -64.3 & -65.0 \\ \hline
30 & -65.9 & -66.3 \\ \hline
40 & -67.2 & -65.6 \\ \hline
50 & -66.7 & -65.3 \\ \hline
\end{tabular}
\end{center}

Any help?

• To be able to test suggestions, a complete MWE would be helpfull. For now I could only suggest to enclose table and caption in a minipage. Aug 31, 2017 at 9:42

\begin{table}[H]
\centering
\captionof{table}{Convergencia pm6-cluster}\label{table:convergencia_cluster_pm6}
\begin{tabular}{|l|l|l|}
\hline
\textbf{nºconf} & \textbf{$\Delta G^0$-SS} & \textbf{$\Delta G^0$-Packmol} \\ \hline
5 & -64.6 & -64.7 \\ \hline
10 & -65.5 & -64.1 \\ \hline
15 & -63.7 & -66.5 \\ \hline
20 & -64.3 & -65.0 \\ \hline
30 & -65.9 & -66.3 \\ \hline
40 & -67.2 & -65.6 \\ \hline
50 & -66.7 & -65.3 \\ \hline
\end{tabular}
\end{table}

of course, for this you need add \usepackage{float} to document preamble. however, such solution (also with use of minipage for the same effect) is -- to my opinion -- against to latex "philosophy" of nice document formatting. I would rather use:

\begin{table}[ht]
\centering
\caption{Convergencia pm6-cluster}
\label{table:convergencia_cluster_pm6}
\begin{tabular}{|l|l|l|}
\hline
\textbf{nºconf} & \textbf{$\Delta G^0$-SS} & \textbf{$\Delta G^0$-Packmol} \\ \hline
5 & -64.6 & -64.7 \\ \hline
10 & -65.5 & -64.1 \\ \hline
15 & -63.7 & -66.5 \\ \hline
20 & -64.3 & -65.0 \\ \hline
30 & -65.9 & -66.3 \\ \hline
40 & -67.2 & -65.6 \\ \hline
50 & -66.7 & -65.3 \\ \hline
\end{tabular}
\end{table}

this allows to float table to the next page (as at first solution) but also enable to fill empty space on previous page with text after inserting a table in document. otherwise you will have there (ugly) empty space.

• I have had too many problems to set tables with that environment, that is why I changed to \begin{center}. I will try it anyway
– user134500
Aug 31, 2017 at 10:48
• for suggested solution you can employ your editor :) find/replace function take less effort as adding minipages to your \begin{center} ... \end{center} (to my opinion) ... Aug 31, 2017 at 10:52

Use a minipage environment to prevent the caption and the table from being separated by a pagebreak:

\begin{minipage}{\textwidth}
\centering
\captionof{table}{Convergencia pm6-cluster}\label{table:convergencia_cluster_pm6}
\begin{tabular}{|l|l|l|}
\hline
\textbf{nºconf} & \textbf{$\Delta G^0$-SS} & \textbf{$\Delta G^0$-Packmol} \\ \hline
5 & -64.6 & -64.7 \\ \hline
10 & -65.5 & -64.1 \\ \hline
15 & -63.7 & -66.5 \\ \hline
20 & -64.3 & -65.0 \\ \hline
30 & -65.9 & -66.3 \\ \hline
40 & -67.2 & -65.6 \\ \hline
50 & -66.7 & -65.3 \\ \hline
\end{tabular}
\end{minipage}
• You might need a \noindent before \begin{minipage}. Aug 31, 2017 at 9:47
• I don't know why minipage produces lot of space below the table
– user134500
Aug 31, 2017 at 10:24
• isn't it more natural to enclose tabular material in table environment (with [H] option?) Aug 31, 2017 at 10:25
• @HernanMiraola Well, the same principle applies, if there isn't room for the image on the page, it will move to the next page. Aug 31, 2017 at 10:55
• @HernanMiraola You have one choice: Let LaTeX do the positioning of tables and figures, or do it yourself. Both posted solutions make you the master general and you are fully resposible for positioning. Including any white space and bad page breaks that arise from it. Sep 3, 2017 at 7:41