0

Is there a piece of code out there for checking that tables have the correct number of columns before trying to compile? I've searched for this error message a million times:

Extra alignment tab has been changed to \cr

And I always end up on this page: Table - Extra alignment tab has been changed to \cr

It's not as straightforward as counting the number of & characters in each line and comparing to \begin{tabular}, because sometimes I have tables with lines like this \multicolumn{3} or this \begin{tabular}{l rr @{\hspace{1em}} r}.

I could write the code myself, but I'm sure I would miss a lot of things. Has anyone written a table checker? Is this more of a meta question? Thanks!

4
  • In texstudio too many & will be marked in red. Mar 9, 2018 at 22:18
  • 3
    to do a full job would require a full tex engine to expand user markup so it isn't clear whether such a thing ca exist other than a simplistic check of & that would catch some cases but give spurious warnings in others Mar 9, 2018 at 22:25
  • Often all the & of a table row are not in the same line of code
    – Fran
    Mar 9, 2018 at 22:25
  • Not sure if it would help, but latexindent aligns ampersands (usually) which can help
    – cmhughes
    Mar 10, 2018 at 17:18

1 Answer 1

2

Life is easier if you are using tblr environment of tabularray package, where number of columns is automatically determined by table contents.

\documentclass{article}

\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{hlines,vlines}
  1 & 2 & 3 & 1 & 2 & 3 & 1 & 2 & 3 & 1 & 2 & 3 & 1 & 2 & 3 & 1 & 2 & 3 & 1 & 2 & 3 & 1 & 2 & 3 & 1 & 2 & 3 & 1 & 2 & 3 \\
\end{tblr}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .