40

I am using the ACM SIG template and trying to create a table of 4 columns.

I get the error mentioned in the title of the question. I know the standard reasons why this error can occur.

But my question is: Is it possible that the template or .cls file is controlling the maximum number of columns in a table ? If it were, would I get a different error than this?

0

8 Answers 8

54

The error can be reproduced by

\documentclass{article}

\begin{document}

\begin{tabular}{c|c}
one & two & three \\
\hline
one & two 
\end{tabular}
\end{document}

The problem is caused by the extra column you try to insert. The tabular environment expects two columns but three is inserted.

1
  • 1
    that's precisely what was happening. in TexShop on mac, the characters for | and l look exactly same.
    – euphoria83
    Commented Oct 18, 2010 at 19:46
4

Another way to get a ! Extra alignment tab has been changed to \cr error is to use an alignment command (\centering, \raggedleft, \raggedright) in the last row of a tabular environment (when using p{} formatting, of course).

For example, this code will give an error:

\begin{tabular}{|p{0.2\textwidth}|p{0.2\textwidth}|}
     A & \centering B \\
    C & D \\    
\end{tabular}

But this code will not:

\begin{tabular}{|p{0.2\textwidth}|p{0.2\textwidth}|}
     \centering A &  B \\
     \centering C & D \\    
\end{tabular}

enter image description here

We can use the environment center to overcome this problem, with the caveat that we will have extra vertical spaces. (needless to say, you may change to c column formatting, if you are willing to give up width control ;))

A quick fix for the problem is to add a zero-width column, e.g., p{0pt}

Quick fix solution:

\begin{tabular}{|p{0.2\textwidth}|p{0.2\textwidth}|p{0pt}}
     \centering A &  \centering B &\\
     \raggedleft C & \raggedright D &\\ 
\end{tabular}

enter image description here

3

Not all extra alignment tab has been changed to \cr errors are found via Google or Bing. Something as simple as defining a macro with arguments and forgetting the argument before the first \\ will reproduce the error.

Same thing with \newcommand.

e.g.,

\def\test#1#2{$\hbox to 4cm{#1}}$}
\begin{tabular}{cccc}
Oh & \test{tested}{} & Oh & \test{Oh} \\
   & \test{testing}{} &   & \test{Ohh}{} \\
\end{tabular} 
18
  • That is the very same error as in the other cases, because you are trying to typeset 8 columns, but only four are expected.
    – Johannes_B
    Commented May 15, 2016 at 10:12
  • @Johannes_B You've been around with TeX for a while now. Could you point me to a relevant piece of information either through tug or any other book or material where the newcommand and this error have been co related with one another? .... The error so far, to my understanding points to a very broad concept I wasn't able to find it but just trough trial and error.
    – doed
    Commented May 15, 2016 at 10:21
  • Your definition wants two arguments, in the first row, the last \test doesn't have a second and uses what comes next. That means the double backslash gets (partly) eaten up and LaTeX doesn't have the information that the line should be broken. Hence it complains that two many columns are used.
    – Johannes_B
    Commented May 15, 2016 at 10:25
  • Try \test{Wombat}\\ Wombat or even use \def\test#1#2{#1\typeout{This is shown in the terminal: #2}} to see that the double backslash is eaten up completely.
    – Johannes_B
    Commented May 15, 2016 at 10:29
  • 1
    But @Johannes_B ok, it complains that two many columns are used.... vague to say the least. And if the information out there is vague then it just defeats the purpose. Who wrote or came up with the idea to have the error extra alignment tab has been changed to \cr then?
    – doed
    Commented May 15, 2016 at 11:20
2

Hi,I had the same question and googled to this page. At last, I solved this problem by add one more c, the correct case should like below:

\documentclass{article}

\begin{document}

\begin{tabular}{c|c|c}
one & two & three \\
\hline
one & two 
\end{tabular}
\end{document}
1
  • I just copy-pasted a beautiful array from stackoverflow, where it displays great, and I too had to add a c to make it display in a standard LaTeX system. Not sure what's going on...
    – PatrickT
    Commented Mar 4, 2018 at 14:48
1

Here's another way you can get this error (the error is still that there are too many columns, but if you're as stupid as I am that isn't obvious):

I was using && instead of & for some reason. So I had twice as many columns as I thought. I couldn't figure out what was wrong for a long time, because all the answers here said "this error is caused by having too many columns!" and I was like, "I don't have too many columns!".

So if anyone out there shares my && disability, hopefully this answer will help you :)

1

Another possible reason is using a \cline{2-3} with {2-3} defining which columns need to be covered by the line. If you have less columns (here: less than 3) than you define in the \cline command, you get this error.

Example with error:

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{ll}
\hline
\textbf{Column 1} & \textbf{Column 2} \\ \hline
Content           & Content           \\ \cline{2-3} % <-- this causes the error
Content           & Content           \\ \hline
\end{tabular}
\end{table}

Example without error:

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{ll}
\hline
\textbf{Column 1} & \textbf{Column 2} \\ \hline
Content           & Content           \\ \cline{2-2}
Content           & Content           \\ \hline
\end{tabular}
\end{table}
1
1

An alternative solution with tblr environment of tabularray package: the number of columns is determined by table contents.

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{tblr}{}
One & Two & Three & Four & Five & Six & Seven & Eight & Nine & Ten \\
One & Two & Three & Four & Five & Six & Seven & Eight & Nine & Ten \\
\end{tblr}

\bigskip

\begin{tblr}{hlines,vlines}
One & Two & Three & Four & Five & Six & Seven & Eight & Nine & Ten \\
One & Two & Three & Four & Five & Six & Seven & Eight & Nine & Ten \\
\end{tblr}

\end{document}

enter image description here

1

For anyone arriving at this error NOT coming from working in a tabular environment, make sure that you aren't using an "&" without escaping it. E.g. you should be using Salt \& Pepper rather than Salt & Pepper.

You must log in to answer this question.

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