# Misplaced \omit in table and {} at the end of a command

The following LaTeX document does not compile.

\documentclass{article}

\usepackage{booktabs}
\usepackage{ltablex}
\usepackage[]{multirow}
\usepackage{lipsum}

\begin{document}

\noindent{}
\begin{tabularx}{\linewidth}{Xl}
\bottomrule{}%
\multicolumn{2}{c}{TESTING}\\*\midrule{}%
\textbf{Left} & \textbf{Right}\\*\toprule{}%
%
\toprule{}%
\multicolumn{2}{c}{\emph{continuing}}\\*\midrule{}%
\textbf{Left} & \textbf{Right}\\*\bottomrule{}%
%
\lipsum[1][1-2] & first  \\\midrule{}%
\lipsum[2][1-2] & second \\\midrule{}%
\lipsum[3][1-2] & third  \\\midrule{}%
\lipsum[4][1-2] & third  \\\bottomrule{}%
\end{tabularx}

\end{document}


pdflatex is giving the error message:

! Misplaced \omit.
\multispan ->\omit
\@multispan
l.26 \end{tabularx}


I have observed that if {}% is removed from the source, it compiles.

What is the explanation for this behaviour?

The real document I am working with is generated by a Haskell program using the HaTeX library, which uses to append {} to commands with no arguments.

• \omit must be the first token in a cell (probably after some expansions). Since {} is not expandable, \omit is no longer the first token in that cell, hence the error about a misplaced \omit. \multicolumn expands to something with \multispan as its first token and \multispan expands to \omit\@multispan, so after two steps of expansion, \multicolumn is turned into something with \omit as the first token. – Skillmon Dec 7 '18 at 13:35
• Well, the Haskell program does wrong. The culprits are precisely those wrong {} tokens. – egreg Dec 7 '18 at 13:40
• Argumentless commands that produce text are in most occasions best followed by {}. Those that don't produce text should not have {} after them, but a simple space. – egreg Dec 7 '18 at 14:01
• In almost all cases, spaces are removed after all command names, i.e. control sequences that are built of a backslash followed by letters. Note that control characters like \\, \> etc. don't discard the following space(s). – siracusa Dec 7 '18 at 16:34
• @Romildo Yes, it's safe for commands whose name consists of letters. The only problem is if the command generates text. But it's quite rare and you Haskell program should not take that case as the general one. Commands to be protected that way can be added as exceptions. – egreg Dec 7 '18 at 23:38

The {} after \noindent does not generate a TeX error, but the newline after it forces bad output, as the paragraph has been started prematurely the newline generates a non-discarded space at the start of the paragraph, which looks a bit like indentation but is not indented by a fixed \parindent it is a word space.

Compare the two paragraphs:

\documentclass{article}

\begin{document}

\noindent
AAA

\noindent{}
AAA
\end{document}


\multicolumn must be first the command (after expansion) in its cell, any non expandable tokens will cause \multicolumn to generate an error, as it is too late to change the cell template.

So the example could be simplified to

\documentclass{article}

\begin{document}

\begin{tabular}{c}
a\\
{}\multicolumn{1}{l}{x}
\end{tabular}

\end{document}


which generates

! Misplaced \omit.
\multispan ->\omit
\@multispan
l.8 {}\multicolumn{1}{l}{x}