使用多列时,列之间的间距不一样。(第 2 列距离第 1 列比距离第 3 列更近。)我怎样才能使它们相同?
\documentclass{article}
\begin{document}
\begin{tabular}{ccc|c}
\hline
\multicolumn{3}{c|}{Here is a long text} & P \\
1 & 2 & 3 & $A$ \\
2 & 1 & 3 & $B$ \\
3 & 1 & 2 & $C$ \\
3 & 2 & 1 & $D$ \\
\hline
\end{tabular}
\bigskip
\begin{tabular}{ccc|c}
\hline
& & & P \\
1 & 2 & 3 & $A$ \\
2 & 1 & 3 & $B$ \\
3 & 1 & 2 & $C$ \\
3 & 2 & 1 & $D$ \\
\hline
\end{tabular}
\end{document}
答案1
我的评论的概念证明答案:
\documentclass{article}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newlength\mylen
\newcommand\seteqwidth[3]
{%
\settowidth#1{#2}%
\setlength#1{\dimexpr(#1-(#3\tabcolsep-\tabcolsep)*2)/#3}%
}
\begin{document}
\begingroup
\seteqwidth\mylen{Here is a long text}{3}
\begin{tabular}{*3{C{\mylen}}|c}
\hline
\multicolumn{3}{c|}{Here is a long text} & P \\
1 & 2 & 3 & $A$ \\
2 & 1 & 3 & $B$ \\
3 & 1 & 2 & $C$ \\
3 & 2 & 1 & $D$ \\
\hline
\end{tabular}
\endgroup
\bigskip
\begin{tabular}{ccc|c}
\hline
& & & P \\
1 & 2 & 3 & $A$ \\
2 & 1 & 3 & $B$ \\
3 & 1 & 2 & $C$ \\
3 & 2 & 1 & $D$ \\
\hline
\end{tabular}
\end{document}