1

I try to make a table with more than two columns as follows

\begin{center}\begin{tabular}{cc}
    Sub & $A_i$ & $B_i$ & $C_i$ & $D_i$ & $E_i$ & $F_i$ & $G_i$ & $H_i$ \\ \hline
    1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\
    1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\ \hline
\end{tabular} \end{center}

But it shows

[4]
! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate 
                             
l.228         Sub & $A_i$ &
                            $B_i$ & $C_i$ & $D_i$ & $E_i$ & $F_i$ & $G_i$ & ...

? 

I want to know how to solve the error. It seems nothing wrong to me. And when I reduce the number of columns to 2, it works fine. It shows me an error when there are more than 2 columns.

4
  • 3
    Load array and use in the table preamble *{9}{c}, not cc.
    – Bernard
    May 23 at 22:17
  • 2
    {cc} means two centred columns. May 23 at 23:04
  • Welcome to TeX.SE.
    – Mico
    May 24 at 4:45
  • 1
    problem solved! thank you May 24 at 6:59

1 Answer 1

1

I suggest you employ a matrix environment (provided by the amsmath package) in an unnumbered displayed equation instead of a tabular environment embedded in a center environment.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for 'matrix' env.
\begin{document}
\[
\begin{matrix} 
% Note: No need for '$' symbols to initiate and terminate inline math mode...
    \mathrm{Sub} & A_i & B_i & C_i & D_i & E_i & F_i & G_i & H_i \\ 
    \hline
    1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\
    1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\ 
    \hline
\end{matrix} 
\]
\end{document}

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.