# Error: \caption outside float

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}

-
The second lacks a \ in begin{table}[h]. –  N.N. Oct 28 '11 at 10:40
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  samcarter May 17 at 9:52

The second table started with

begin{table}[h]


\begin{table}[h]


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

-

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}

-
Should a table caption not be placed above the table? Not that this is made easy by LaTeX. –  Martin Scharrer Nov 1 '11 at 10:49
@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 1 '11 at 11:03