所以我有这个代码:
\begin{center}
\footnotesize
\begin{tabular}{| c | c c c |}
\hline
\multirow{3}{*}{Equipment acquired at start of year} & \multicolumn{3}{c|}{Replacement cost (\$) for given years}\\
\cline{2-4}
& 1 & 2 & 3\\
\hline
1 & 4000 & \multicolumn{1}{|c|}{5400} & 9800\\
2 & 4300 & \multicolumn{1}{|c|}{6200} & 8700\\
3 & 4800 & \multicolumn{1}{|c|}{7100} & -\\
4 & 4900 & \multicolumn{1}{|c|}{-} & -\\
\hline
\end{tabular}
\end{center}
[我想要的是,第3列的宽度像1和2下的列一样均匀。另外,我希望“在年初获得的设备”位于两个多行之间的中心。
有什么想法吗? xD
这里有两个选项,两个选项都使用booktabs
来构造booktabs
。 tabular
建议避免使用垂直规则,因为booktabs
的柱状结构必定会使其自身与列中的元素进行水平对齐,并且各列之间的whitespace会提供视觉上的分隔。
tabular
在第一个选项中,第2-4列的标题被堆叠以自然地适合结果宽度。在第二个选项中,为列2-4指定了固定的列宽\documentclass{article}
\usepackage{makecell,booktabs,array}
\begin{document}
% This construction does not require the array package
\begin{tabular}{ *{4}{c} }
\toprule
& \multicolumn{3}{c}{\makecell[c]{Replacement cost \\ for given years (\$)}} \\
\cmidrule{2-4}
\smash{\makecell[cb]{Equipment acquired \\ at start of year}} & 1 & 2 & 3 \\
\midrule
1 & 4000 & 5400 & 9800 \\
2 & 4300 & 6200 & 8700 \\
3 & 4800 & 7100 & -- \\
4 & 4900 & -- & -- \\
\bottomrule
\end{tabular}
\bigskip
% This construction requires the array package
\begin{tabular}{ c *{3}{>{\centering\arraybackslash}p{1cm}} }
\toprule
& \multicolumn{3}{c}{\makecell[c]{Replacement cost \\ for given years (\$)}} \\
\cmidrule{2-4}
\smash{\makecell[cb]{Equipment acquired \\ at start of year}} & 1 & 2 & 3 \\
\midrule
1 & 4000 & 5400 & 9800 \\
2 & 4300 & 6200 & 8700 \\
3 & 4800 & 7100 & -- \\
4 & 4900 & -- & -- \\
\bottomrule
\end{tabular}
\end{document}
。您可以根据需要调整此宽度,具体取决于您想要伸展这些列的数量。