3

I've got the following code:

\begin{center}
\sffamily
\captionof{table}{Codexample}
\begin{tabular}{ll}
\topule[2.5pt]
exampleline & example \\
...
\bottomrule[2.5pt]
\end{tabular}
\end{center}

I've added the \captionof{table}{..} in order to give my table a heading. I assume that the whole table is a floating object (I hope this is the right English expression) and LaTex decides more or less where to put it.

My problem is: In my document I've got some text before the table. LaTex produces an ugly PDF document: The title of the table is on one page and the table itself on the next page. How to correct that?

user50224
  • 417
  • 1
  • 3
  • 11
  • 3
    Use \begin{table}\centering and \end{table} instead of center; change \captionof{table} into \caption. – egreg Jul 08 '14 at 12:05

1 Answers1

6

Simply use

\begin{table}
\caption{Codexample}
\begin{tabular}{ll}
\toprule
exampleline & example \\
...
\bottomrule
\end{tabular}
\end{table}

The table will float and be placed at a convenient position. You can also say

\begin{table}[htp]

so that LaTeX will try placing the table at the spot. See

for more information about floats.

As an aside, \toprule[2.5pt] will produce too thick a rule.

egreg
  • 1,121,712