# Make each column of a table have same width

I have a table as follows:

  &$\begin{array}{c|cc|cc} & x & \multicolumn{1}{c}{y} & i & 0 \\ \hline x & 0 & \multicolumn{1}{c}{} & -49 & \\ y & & \multicolumn{1}{c}{0} & & \\ \cline{4-5} i & 49 & & 0 &-2\\ 0 & & & 2 & 0 \end{array}$


Is there a way to make each column have same width?

-
Please read the documentation of array. –  Marco Daniel Mar 4 '12 at 20:34
Sorry, have not found anything which helps... –  SoftTimur Mar 4 '12 at 20:40
This question needs considerable clarification. Ideally you should provide us with a minimum complete document that illustrates what you have so far, and, perhaps, a diagram of what you're trying to achieve. All I get from the code you supply is a jumble. –  Brent.Longborough Mar 4 '12 at 20:41
Documentation of array Table 1 -- column type p{width} –  Marco Daniel Mar 4 '12 at 20:47
have you looked at the tabularx documentation? –  cmhughes Mar 4 '12 at 22:31

For fixed-column width with known column entries, I would suggest using \settowidth{<length register>}{<stuff>} to extract the width of the widest element in your array. Alternatively, the calc package provides \widthof{<stuff>} that provides a similar work-around:

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\newcolumntype{C}[1]{>{\centering\arraybackslash$}p{#1}<{$}}

\begin{document}

\newlength{\mycolwd}% array column width
\settowidth{\mycolwd}{$-49$}% "width" of $-49$; largest element in array
$\begin{array}{C{\mycolwd}*{4}{|C{\mycolwd}}} & x & \multicolumn{1}{c}{y} & i & 0 \\ \hline x & 0 & \multicolumn{1}{c}{} & -49 & \\ y & & \multicolumn{1}{c}{0} & & \\ \cline{4-5} i & 49 & & 0 & -2 \\ 0 & & & 2 & 0 \end{array}$

\end{document}


For example, using calc, one could use

  \begin{array}{C{\widthof{$-49$}}*{4}{|C{\widthof{$-49$}}}}


Note the use of *{<num>}{<col spec>} which repeats <col spec> a total of <num> times. It improves consistency and ease of updating.

-

It's quite complicated to get the same width of all columns of an alignment without the user telling TeX what the desired column width or the preferred total width of the alignment is.

It's indeed possible by typesetting the alignment twice, the first one for gathering all the cells and measuring them. However, for a simple matrix as yours, it's probably easier to state a size, guessing at the widest entry:

\documentclass{article}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash$}p{#1}<{$}}

\begin{document}

$\begin{array}{C{1.8em}|C{1.8em}C{1.8em}|C{1.8em}C{1.8em}} & x & \multicolumn{1}{c}{y} & i & 0 \\ \hline x & 0 & \multicolumn{1}{c}{} & -49 & \\ y & & \multicolumn{1}{c}{0} & & \\ \cline{4-5} i & 49 & & 0 &-2\\ 0 & & & 2 & 0 \end{array}$

\end{document}


Just remember that, approximately, 1em is as wide as a capital M. As long as one entry in a column is not \multicolumn, you can use c for the argument of \multicolumn, because the effect will be exactly the same.

-