21

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.

0

1 Answer 1

24

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 [.

3
  • Why doesn't this problem arise when there is only one row, though?
    – Sverre
    Jul 20, 2012 at 16:02
  • @Sverre With one row you dont have \\ before the [. Jul 20, 2012 at 16:02
  • 4
    @Sverre It's the second [ that causes the issue: the first one cannot be an optional argument as there is no preceding \\ .
    – Joseph Wright
    Jul 20, 2012 at 16:03

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