LaTeX:表格中带有 makecell 的均匀间隔的单元格

问题描述

我正在尝试在 LaTeX 中创建一个表格,其中第 2 行的单元格 X 均匀分布。下面的 MWE 返回具有不同宽度的 row2 的单元格。我怀疑包 makecell 对此负责。有人能解释一下我是如何让第 2 行的单元格均匀分布的吗?

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}

MWE 返回给我的内容的屏幕截图:

Screenshot of above MWE table

解决方法

一种可能的方法是使用固定列:

\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