36

When I add the following table (table1 shown below) I don't get any error, but when adding table2 (shown below) I get the error i)\caption outside float. \caption ii) Undefined control sequence \caption. What is the difference between these two table definitions? These two seems same to me.

latex code for table1 :

\begin{table}[h]
\begin{center}
\begin{tabular}{| p{2.5cm}| p{2.5cm} | p{2.5cm} |}
\hline
\textbf{AAA} & \textbf{BBB} & \textbf{CCC} \\
\hline
DDD   & 111 & 333\\ \hline
EEE   & 222 & 444\\ \hline
\end{tabular}
\end{center}

\caption{Caption1}
\label{table1}

\end{table}

................................................................

latex code for table2:

begin{table}[h]
\begin{center}
\begin{tabular}{| p{2.5cm}| p{2.5cm} |}
\hline
\textbf{GGG} & \textbf{HHH} \\
\hline
III                    &              113\\ \hline
JJJ                    &              234\\ \hline
KKK                    &              345\\ \hline
\end{tabular}
\end{center}
\caption{Caption2}
\label{table2}
\end{table}
David Carlisle
  • 757,742
RIchard Williams
  • 1,219
  • 3
  • 14
  • 18

2 Answers2

22

Check carefully your document when such errors pop out; before the editing to the question, the second begin{table} wasn't preceded by the backslash. In this case LaTeX is happy to print "begintable[h]" and then start the center environment.

If you had proceded on by hitting return at the error message you'd have seen another one telling you that the document environment had been closed by table.

By the way, don't use the center environment in this situation:

\begin{table}
\centering
<table data>
\caption{The caption}\label{thelabel}
\end{table}
egreg
  • 1,121,712
  • Should a table caption not be placed above the table? Not that this is made easy by LaTeX. – Martin Scharrer Nov 01 '11 at 10:49
  • 1
    @MartinScharrer It's a style decision. The standard classes provide for captions below in both cases (they set \belowcaptionskip to zero). Think to a paper where there are tables and figures side by side: captions will be set all above or below. The caption package has the options position=top and position=bottom that can be set separately for figures and tables. – egreg Nov 01 '11 at 11:03
20

The second table started with

begin{table}[h]

instead of

\begin{table}[h]

meaning it missed a \ and that was what gave the error of a caption outside a float.

N.N.
  • 36,163