我有一张表,其乳胶代码是:
\begin{table}[]
\centering
\begin{tabular}{ccccc}
\hline
\multirow{3}{*}{ABCD} & first col & second col & \multicolumn{2}{c}{third col} \\ \cline{2-5}
& \multicolumn{4}{c}{DF} \\ \cline{2-5}
& 1 & 2 & 3 & 4 \\ \cline{1-1}
AB & 98 & 65 & 33 & 64 \\
CD & 45 & 44 & \multicolumn{2}{c}{-} \\
EF & 56 & 67 & \multicolumn{2}{c}{-} \\ \hline
\end{tabular}
\end{table}
最终的乳胶表如下:
3 和 4 之间的间距与 1 和 2 之间的间距不同。这是因为 1、2 分别位于第一列和第二列,而 3 和 4 位于第三列。如何增加第三列的宽度,以使列宽 1-2-3-4 均匀一致。
答案1
\documentclass[12pt,oneside]{book}
\usepackage{tabularx, multirow,booktabs}
\begin{document}
\begin{tabularx}{0.6\textwidth}{*{5}{>{\centering\arraybackslash}X}}
\toprule
\multirow{2}{*}{ABCD}
& first col
& second col
& \multicolumn{2}{c}{third col} \\ \cmidrule{2-5}
& \multicolumn{4}{c}{DF} \\ \cmidrule{2-5}
& 1
& 2
& 3
& 4 \\
AB
& 98
& 65
& 33
& 64 \\
CD
& 45
& 44
& \multicolumn{2}{c}{-} \\
EF
& 56
& 67
& \multicolumn{2}{c}{-} \\ \bottomrule
\end{tabularx}
\end{document}
编辑
\documentclass[12pt,oneside]{book}
\usepackage{tabularx, multirow,booktabs}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
colspec = cccccc,
cell{1}{1} = {r=3}{c}, % multirow
cell{1}{4} = {c=3}{c}, % multicolumn
cell{2}{2} = {c=5}{c}, % multicolumn
cell{5,6}{5} = {c=1}{c}, % multicolumn
hspan = even, % distribute extra space evenly
colsep = 4pt,
}
\hline
ABCD
& {first \\col}
& {second\\ col}
& {third \\col} \\ \cline{2-6}
& DF \\ \cline{2-6}
& 1
& 2
& 3 &
& 4 \\
AB
& 98
& 65
& 33 &
& 64 \\
CD
& 45
& 44 &
& - \\
EF
& 56
& 67 &
& - \\ \hline
\end{tblr}
\end{document}