[Tex/LaTex] Tabular columns have different width

columnsmulticoltables

I have the following simple tabular environment:

\begin{center}
\small
\begin{tabular}{|c|c|c|}
\hline
\multirow{2}{*}{$cm(ag)$}  & \multicolumn{2}{|c|}{Number of agents in}\\ \cline{2-3}
 & $\mathcal{B}_i(\alpha)$ & $\mathcal{B}'_i(\alpha)$ \\ \hline
HA & 10& 0 \\ \hline
AD & 5 & 2 \\ \hline
H  & 0 & 3 \\ \hline
\end{tabular}
\end{center}

And this is the result:

enter image description here

Why the two columns in the figure are not equally wide (one would expect it naturally to happen)?

Best Answer

The third column is particularly wide as it has been stretched by the multicolumn entry. It is best to ensure that the natural width of a spanning cell is less than the width of the columns it is spanning.

Note that even without the spanning head the third column would be wider than second column as the heading is wider because of the '

In multicolumn, only use | on the right edge of a cell, except for the first column, otherwise you get duplicated double thick lines as seen in your image.

I left $cm$ as I do not know what it means but it looks a bit odd: if cm is to be read as a single word rather than c times m then it ought to be \mathit{cm}.

Here I used dcolumn to align the digits of the numbers and force the natural widths of the columns to be greater than the heading.

I also added some extra padding to keep the horizontal rules off the text.

enter image description here

\documentclass{article}
\usepackage{dcolumn,multirow}
\begin{document}

\begin{center}
\small
\setlength\extrarowheight{2pt}
\begin{tabular}{|c|D{.}{}{5.5}|D{.}{}{5.5}|}
\hline
\multirow{2}{*}{$cm(ag)$}  & \multicolumn{2}{c|}{Number of agents in}\\ \cline{2-3}
 & \multicolumn{1}{c|}{$\mathcal{B}_i(\alpha)$} & 
\multicolumn{1}{c|}{$\mathcal{B}'_i(\alpha)$} \\ \hline
HA & 10& 0 \\ \hline
AD & 5 & 2 \\ \hline
H  & 0 & 3 \\ \hline
\end{tabular}
\end{center}
\end{document}
Related Question