Wednesday, February 25, 2009

Table lines starting with square bracket

this one does not compile:

\documentclass{article}
\begin{document}
\begin{tabular}{ll}
a & b \\
[c] & d \\
\end{tabular}
\end{document}

if required, one can specify the vertical gap between lines in a table using
\\[len]

LaTeX removed the newline and whitespace to interpret the table as having a \\[c] entry, and there exists no length "c".

So the solution is to write the initial square bracket into curly braces. This way it is not interpreted as the beginning of the optional argument of the newline command.

\documentclass{article}
\begin{document}
\begin{tabular}{ll}
a & b \\
{[}c] & d \\
\end{tabular}
\end{document}

Thanks to Werner Grundlingh for showing me the problem source.

7 comments:

kyanh said...

You may simplify use \relax

a & b \\ \relax
[c] & d

Anonymous said...

Thanks, very helpful.

Gopalakrishna said...

Very useful when using with XeLatex especially when we use below syntax for non-english based Song latex package
\begin{tabular}
\[గా గ గా మ గ]
\end{tabular}

This solution is helpful as this is required in cases for typesetting carnatic music documents
Gopalakrishna Palem
Creator of CFugue Carnatic Music Programming Library for C++
http://gpalem.web.officelive.com/CFugue.html

Anthony said...

I found that prepending a tilde works as well.

a & b\\
~[c] & d

Anonymous said...

title results in small space in front of [string]

Anonymous said...

Thanks all - very helpful.

I find the tilde does something odd with the spacingso am going for the {[}.

Werner Grundlingh said...

Also see “[” as first character in table row.