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}
2
  • 2
    The second lacks a \ in begin{table}[h].
    – N.N.
    Oct 28, 2011 at 10:40
  • 5
    I'm voting to close this question as off-topic because it is caused by a simple typo. May 31, 2017 at 12:39

2 Answers 2

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.

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}
2
  • Should a table caption not be placed above the table? Not that this is made easy by LaTeX. Nov 1, 2011 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 1, 2011 at 11:03

Not the answer you're looking for? Browse other questions tagged .