Why does an empty tabularx throw an error ? (by empty, I mean only space, no newline)




\begin{tabular}{|c | c|}
\end{tabular}                                        % <-- Works

\begin{tabular}{|c | c|}\end{tabular}                % <-- Works

\begin{tabularx}{\textwidth}{|c | c|}
\end{tabularx}                                        % <-- Works

\begin{tabularx}{\textwidth}{|c | c|}\end{tabularx}   % <-- Does not work


(This is particulary frustrating with \ExplSyntaxOn)

  • 5
    "why" is probably that it didn't occur to me to test for this and trap it. – David Carlisle Apr 1 at 9:37
  • Well... I guess it's probably a good reason ^^' – hl037_ Apr 1 at 9:54
  • 3
    This code has been available for almost 30 years and you are the first person to report this issue:-) – David Carlisle Apr 1 at 9:56

"why" is probably that it didn't occur to me to test for this and trap it.

Looking at tracing all the reason is that in

\begin{tabularx}{\textwidth}{|c | c|}\end{tabularx}

The entire body (that tabularx needs to grab as a macro argument) is {|c | c|} and tex silently drops brace groups that surround an entire delimited argument, so this is passed to tabularx as

\begin{tabularx}{\textwidth}|c | c|\end{tabularx}

and things go wrong.

If you are generating this and there is a chance it might be empty you could use the optional argument

\begin{tabularx}{\textwidth}[c]{|c | c|}\end{tabularx}   % <-- Does not work

works for example.

I can probably catch this in a future release.

possible fix


  \TX@typeout{Target width: ##1 = \the\TX@target}%
\foo{ }

\begin{tabularx}{\textwidth}{|c | c|}\end{tabularx}   % <-- Does not work

  • In my case, it's not that a big deal once i know it can't be empty. I actually encountered it when debugging a macro to generate table, and I stuck on this error not knowing that an empty tabularx would error – hl037_ Apr 1 at 9:57
  • 1
    @hl037_ see update – David Carlisle Apr 1 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.