[Tex/LaTex] Brackets in first column in table give “Missing number, treated as zero” error

bracketserrorstables

Possible Duplicate:
Error with table

I'm writing a table with 4 columns and 1 row. The first column starts with a bracket. It compiles without issues:

\documentclass{article}
\begin{document}
\begin{tabular}{l l l l}
[k]bbb & `def' & [h]bbb & `def' \\
\end{tabular}
\end{document}

If I add another row like that, on the other hand, I receive an error message.

\documentclass{article}
\begin{document}
\begin{tabular}{l l l l}
[k]bbb & `def' & [h]bbb & `def' \\
[k]ccc & `def' & [h]ccc & `def' \\
\end{tabular}
\end{document}

! Missing number, treated as zero.

I can avoid the issue by adding some curly braces to the first column, but I'm curious what's going on with LaTeX and brackets in tables here.

Best Answer

LaTeX sees the [ (from the second row) as the beginning of the optional argument for \\ and expects a length to follow; since the following token is k, an error is triggered. To prevent this, you can use braces:

\documentclass{article}
\begin{document}
\begin{tabular}{l l l l}
{[k]}bbb & `def' & [h]bbb & `def' \\
{[k]}ccc & `def' & [h]ccc & `def' \\
\end{tabular}
\end{document}

With only one row there's no problem (in fact, the braces around the [k] of the first row in my example can be suppressed) since there's no \\ before the character [.