"[" as first character in table row

Here is a MWE that illustrates your problem:

\documentclass{article}
\begin{document}
\begin{table}
    \begin{tabular}{r|r}
        [some text ] & ... \\
        [more text ] & ... \\
    \end{tabular}
\end{table}
\end{document}

The issue is that \\[1 in] is used at the end of a line to skip 1in (for instance) of additional vertical space. So \\ is a macro and [1in] is an optional argument to that macro.

When TeX reads \\, then newline, then [, it ignores the newline (as it normally does with all whitespace after a macro) and proceeds as if it were expanding \\[more text ]. But this clearly doesn't make any sense since more text is not a length, in particular it doesn't start with a number. Hence the error: Missing number, treated as zero. Illegal unit of measure.

It wasn't reproduced in your original MWE because you had only one line with bracketed text at the beginning and \\ at the end. It happens between the end of one line and the beginning of another.

As Sigur suggests, you can keep TeX from expanding this way by putting braces around the bracketed text. TeX will expand \\{[more text ]} the expected way since it doesn't "look" like an optional argument is being used anymore. egreg's suggestion of \\\relax will similarly inhibit the macro processor from reading the bracketed text as an optional argument.


No error for me.

Anyway, you can protect with braces { }.

 {[some text]}

edit: as suggested by @tohecz here is the right solution


The problem is, as Matthew Leingang explains, that \\ looks for a following bracket for a vertical spacing specification.

The best solution, which works in all cases, be they in tabular, array and even eqnarray (which shouldn't be used anyway), is to add \relax after \\, when a [ follows:

\documentclass{article}
\begin{document}
\begin{table}
    \begin{tabular}{r|r}
        [some text] & ... \\ \relax
        [more text] & ... \\ 
    \end{tabular}
\end{table}
\end{document}

enter image description here

It's a bit of a nuisance, but the case shouldn't be so frequent.

Note that amsmath environments don't suffer from this problem:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
v&=\begin{bmatrix}
  a\\
  [b]\\
  c
\end{bmatrix}\\
[w]&=x
\end{align*}
\end{document}

enter image description here

Tags:

Tables