# LaTeX table checker?

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!

• In texstudio too many & will be marked in red. – user36296 Mar 9 '18 at 22:18
• 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 – David Carlisle Mar 9 '18 at 22:25
• Often all the & of a table row are not in the same line of code – Fran Mar 9 '18 at 22:25
• Not sure if it would help, but latexindent aligns ampersands (usually) which can help – cmhughes Mar 10 '18 at 17:18