“[” as first character in table row

Whenever I try to compile a table that has a "[" as first character in a row it gives me the error:

Missing number, treated as zero.
Illegal unit of measure

Example:

\begin{table}[htb]
\centering
\begin{tabular}{r|r}
[some text ] & ... \\
[some more text ] & ...
\end{tabular}
\caption{...}
\label{tab:...}
\end{table}

How can I print "[" as first character in a row?

-

No error for me.

Anyway, you can protect with braces { }.

{[some text]}

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

-
Yes, this works. Ty –  Mq_ Jan 24 '13 at 19:07
Put \relax after \\, it's better. –  egreg Jan 24 '13 at 19:23
@Sigur The original example doesn't show the problem. It's for a [ after \\ that the problem shows. It is cured simply by saying \\ \relax –  egreg Jan 24 '13 at 20:56
@Sigur Of course you don't need \\ to terminate the last line unless you have an \hline after it. But the \relax is needed only if a square bracket follows, instead of your braces –  egreg Jan 24 '13 at 21:00
Please remember that the solution with {} is wrong in math mode (array and friends), as shown here: tex.stackexchange.com/questions/86385/… –  tohecz Jan 26 '13 at 16:20

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}

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}

-

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.

-
I think it's much easier to remember to use {} (an idiom that solves some other problems too) than to remember \relax. But it's nice to know both. –  Ethan Bolker Jan 24 '13 at 23:16
@EthanBolker It's better to use \relax It doesn't make any difference here but if you are using array rather than tabular or a math column in a tabular with >{\$} or similar {} can alter the spacing whereas \relax will not. –  David Carlisle Jan 26 '13 at 15:19
Please remember that the solution with {} is wrong in math mode (array and friends), as shown here: tex.stackexchange.com/questions/86385/… –  tohecz Jan 26 '13 at 16:21