Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
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

2 Answers 2

up vote 8 down vote accepted

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.

share|improve this answer

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}
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.