# Multicolumn width uneven

I am trying to create a table with this code;

\begin{table}[ht]
\centering\begin{tabular}{|c|c|c|c|c|}
\hline
Mean Partnership Duration & \multicolumn  {4}{c|}{\centering Number of simulations resulting in an epidemic}\\

\cline{2-5}
\hline
1 & data1 & data2 & data 3 & data4\\
\hline
2 & data1 & data2 & data 3 & 4\\
\hline
3 & data1 & data2 & data 3& 4\\
\hline
4 & data1 & data2 & data 3& 4\\
\hline
\end{tabular}
\caption{This is the ideal table}
\label{My table}
\end{table}



But the 4th subcolumn labelled 'head 4' is larger than the other subcolumns. I want all 4 columns to be equal in width, Any advice? All the best,

• Welcome. Does this (tex.stackexchange.com/questions/5017/…) answer your question? Mar 29, 2021 at 20:14
• @DavidCarlisle apologies I meant Multicolumn Mar 29, 2021 at 21:07
• Hi! Now you have three answers :-). You may consider to up-vote each of them you liked ( by clicking on up-triangle at top left side of answers) and accept one of the, which solve your problem on the best way ( by clicking on check mark at top left side of selected answer). Mar 30, 2021 at 10:44

With use of the makecell and tabularx packages:

\documentclass[12pt]{article}
\usepackage{makecell, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
\begin{table}[ht]
\centering
\setcellgapes{3pt}
\makegapedcells
\begin{tabularx}{\linewidth}{|*{5}{C|} }
\hline
\makecell{Mean\\ Partnership\\ Duration}
& \multicolumn{4}{c|}{Number of simulations resulting in an epidemic}\\
\cline{2-5}
\hline
1   & data 1 & data 2 & data 3 & data4\\
\hline
2   & data 1 & data 2 & data 3 & 4\\
\hline
3   & data 1 & data 2 & data 3 & 4\\
\hline
4   & data 1 & data 2 & data 3 & 4\\
\hline
\end{tabularx}
\caption{This is the ideal table}
\label{My table}
\end{table}
\end{document}


• That is excellent thanks! Mar 30, 2021 at 9:50

Define a new column type (package array) using an m column of the desired width. (m will center vertically the multicolumn cell).

\newcolumntype{C}{>{\centering \arraybackslash}m{0.2\textwidth}}


Using the same package it is possible expand the cells vertically

\renewcommand{\arraystretch}{<a number>}


\documentclass[12pt,a4paper]{article}

\usepackage{showframe} % show margins

\newcolumntype{C}{>{\centering \arraybackslash}m{(\textwidth-(6\arrayrulewidth)-(10\tabcolsep))/5}}

\renewcommand{\arraystretch}{1.8} %<<<<<<<<<<<<<<< optional

\begin{document}

\begin{table}[ht]
\centering
\begin{tabular}{|C|C|C|C|C|}
\hline
Mean Partnership Duration & \multicolumn{4}{c|}{Number of simulations resulting in an epidemic}\\
\cline{2-5}
\hline
1 & data1 & data2 & data 3 & data4\\
\hline
2 & data1 & data2 & data 3 & 4\\
\hline
3 & data1 & data2 & data 3& 4\\
\hline
4 & data1 & data2 & data 3& 4\\
\hline
\end{tabular}
\caption{This is the ideal table}
\label{My table}
\end{table}

\end{document

• Your tabular is too wide. You should replace 0.2\textwidth by (\textwidth-(6\arrayrulewidth)-(10\tabcolsep))/5. Mar 30, 2021 at 9:06

With {NiceTabular} of nicematrix (you need several compilations).

 \documentclass[12pt,a4paper]{article}
\usepackage{nicematrix}

\begin{document}

\renewcommand{\arraystretch}{1.8}

\begin{table}[ht]
\centering
\begin{NiceTabular}{ccccc}[hvlines,columns-width=auto]
\Block{2-1}{}
\Block{}{Mean\\ Partnership\\ Duration} & \Block{1-4}{Number of simulations resulting in an epidemic}\\
1 & data1 & data2 & data 3 & data4\\
2 & data1 & data2 & data 3 & 4\\
3 & data1 & data2 & data 3& 4\\
4 & data1 & data2 & data 3& 4\\
\end{NiceTabular}
\caption{This is the ideal table}
\label{My table}
\end{table}

\end{document}


The key hvlines draws all the rules, excepted in the blocks created by Block (that's why I have added an empty block \Block{2-1}{} to avoid a rule under the left-uppermost cell.

• Thanks for the help! Mar 30, 2021 at 9:51