[Tex/LaTex] How to control table and its title to appear on the same page

tables

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

enter image description here

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?

Best Answer

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