LaTeX: evenly spaced cells with makecell in table

Viewed 1523

I'm trying to create a table in LaTeX with evenly spaced cells X for row2. The below MWE returns the cells of row2 with different widths. I suspect that the package makecell is responsible for this. Could somebody explain how I get my cells in row 2 evenly spaced?

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{makecell}


\begin{document}

\begin{table}[h!]
\centering
\begin{tabular}{ l | c | c | c | c }

row1& 
\multicolumn{2}{c|}{\makecell{multicolumn1}}&
\multicolumn{2}{c}{\makecell{multicolumn2 \\with more text than column1}}\\

row2 & X & X & X & X\\

\end{tabular}
\end{table}

\end{document}

Screenshot of what the MWE returns for me:
Screenshot of above MWE table

1 Answers

One possible approach is to use columns of fixed with:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{makecell}

\usepackage{array}
\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}

\begin{document}


\begin{table}[h!]
\centering
\begin{tabular}{ l | x{2cm} | x{2cm} | x{2cm} | x{2cm} }
row1& 
\multicolumn{2}{c|}{multicolumn1}&
\multicolumn{2}{c}{\makecell{multicolumn2 \\with more text than column1}}\\
row2 & X & X & X & X\\
\end{tabular}
\end{table}

\end{document}

enter image description here

Related