tags:

views:

1858

answers:

2

I'm trying to add a caption to a table in latex, however it throws this error "! LaTeX Error: \caption outside float." From the error I am guessing ti means that it is outside the table, but I have clearly put it inside.

\begin{tabular}{|c|c|c|c|c|c|}
\caption{Table1}
Potentiometer & Resistance  & \multicolumn{2}{c}{Calculated V\textsubscript{32}} & \multicolumn{2}{c|}{Measured V\textsubscript{32}}\\ \cline{3-6}
Position & R\textsubscript{34} & Amplitude & Phase & Amplitude & Phase\\ \hline \hline
1 & 303.8 & & 2.73 & 28.2 & 2.51\\
2 & 1.141k & & 1.81 & 28.2 & 1.63\\
3 & 3.453k & & 0.79 & 28.2 & 0.5\\
4 & 5.33k & & 0.53 & 28.2 & 0.38\\
5 & 7.45k & & 0.38 & 28.2 & 0.25\\
6 & 9.54k & & 0.30 & 28.2 & 0.13\\
7 & 10.84k & & 0.27 & 28.2 & 0.13\\
\hline
\end{tabular}
+8  A: 

The tabular environment won't take a caption. You need to do something like this:

\begin{table}
\begin{tabular}{|c|c|c|c|c|c|}
Potentiometer & Resistance  & \multicolumn{2}{c}{Calculated V\textsubscript{32}} & \multicolumn{2}{c|}{Measured V\textsubscript{32}}\\ \cline{3-6}
Position & R\textsubscript{34} & Amplitude & Phase & Amplitude & Phase\\ \hline \hline
1 & 303.8 & & 2.73 & 28.2 & 2.51\\
2 & 1.141k & & 1.81 & 28.2 & 1.63\\
3 & 3.453k & & 0.79 & 28.2 & 0.5\\
4 & 5.33k & & 0.53 & 28.2 & 0.38\\
5 & 7.45k & & 0.38 & 28.2 & 0.25\\
6 & 9.54k & & 0.30 & 28.2 & 0.13\\
7 & 10.84k & & 0.27 & 28.2 & 0.13\\
\hline
\end{tabular}
\caption{Table1}
\label{tab:xyz}
\end{table}
Dave
+1. Stick a \label{} in there while your at it. It rotten style to put in a float and not refer to it at least once.
dmckee
I moved the caption to the bottom because that's where it's expected by default (the spacing will be wrong otherwise). If you want to move it to the top, look at the caption package.
Will Robertson
+5  A: 

If you don't want to use a "float" (e.g. table or figure) that will "float away" from the place you define it, you can add

\usepackage{capt-of}

in the preamble and then do something like

\begin{center}
  \captionof{table}{Caption text goes here}
  \label{table1} % for use in \ref{table1} if you want to refer to the table number
  \begin{tabular}{|c|c|c|c|c|c|}
  % etc.
  \end{tabular}
\end{center}

to add a auto-numbered caption to a non-float.

Jouni K. Seppänen
New one by me. I would discourage this in general---TeX knows a *lot* about good layout---but it is nice to know its there.
dmckee
Again, don't forget to ensure that the spacing of the caption is correct for being placed above the tabular; by default it's expected below.
Will Robertson