我有一张类似的桌子多行表格格式我可以按照接受的答案中的建议创建其中的一部分\makecel
,但是有小计类型的行,然后在最后两行中最后两列需要合并。我已经这样做了,但没有水平和垂直线,需要使它看起来像这幅图,有人可以指导我像这样格式化它吗(抱歉涂黑了值,这是我的论文结果表):
以下是未添加小计行且未合并列的部分代码:
\begin{document}
\begin{table}[htb]
\resizebox{\columnwidth}{!}{%
\centering\small\sffamily%
\setlength\aboverulesep{1ex}
\setlength\belowrulesep{1ex}
\renewcommand{\cellalign}{lc}
\setlength\arrayrulewidth{0.5pt}
\begin{tabular}{ >{\rule[-0.35cm]{0pt}{0cm}}m{1cm}|m{1cm}|m{2cm}}
\toprule[2pt]
Xxxxxx & Xxxxx & xxxxx xxxx xxxx x \\
\midrule[0.5pt]
Xxxxx & \makecell{Xxxxxx xxxxx \\ Xxxxxxxxxxxx \\ Xxxxxxxx \\ Xxxxxxxxxxxxxxxxx \\ Xxxxxxxxxxxxxxxxxx \\ Xxxxxxxxxxxxxxx } & \makecell{xxxxxx \\ xxxxxx \\ xxxxx \\ xxxxx \\ xxxxx \\ xxxxx} \\%
Xxxxxxxxxxxxxxxx & xxxxxx & \\
Xxxxxxxxxxxxxxxxx & xxxxxx & \\
\bottomrule[2pt]%
\end{tabular}%
}
\caption{xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.}
\label{tab:res}
\end{table}%
\end{document}
答案1
如果我理解正确的话,您正在寻找\multicolumn
(和\cline
)。
\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs,array,makecell}
\begin{document}
\begin{table}[htb]
\resizebox{\columnwidth}{!}{%
\centering\small\sffamily%
\setlength\aboverulesep{1ex}
\setlength\belowrulesep{1ex}
\renewcommand{\cellalign}{lc}
\setlength\arrayrulewidth{0.5pt}
\begin{tabular}{ >{\rule[-0.35cm]{0pt}{0cm}}m{3cm}|m{3cm}|m{3cm}}
\toprule[2pt]
Xxxxxx & Xxxxx & xxxxx xxxx xxxx x \\
\midrule[0.5pt]
Xxxxx & \makecell{Xxxxxx xxxxx \\ Xxxxxxxxxxxx \\ Xxxxxxxx \\ Yyyyxxxxxxxxxxxxx \\ Xxxxxxxxxxxxxxxxxx \\ Xxxxxxxxxxxxxxx } & \makecell{xxxxxx \\ xxxxxx \\ xxxxx \\ xxxxx \\ xxxxx \\ xxxxx} \\\cline{2-3}
& \multicolumn{2}{c}{Zzzzzzz}\\\midrule %new row
Xxxxxxxxxxxxxxxx & \multicolumn{2}{c}{xxxxxx} \\
Xxxxxxxxxxxxxxxxx & \multicolumn{2}{c}{xxxxxx} \\
\bottomrule[2pt]%
\end{tabular}%
}
\caption{xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.}
\label{tab:res}
\end{table}%
\end{document}
答案2
通过使用multirow
和tabularx
,删除垂直线(我认为垂直线不好看并且降低了表格的专业外观),并且不调整表格宽度,表格变成:
\documentclass{article}
\usepackage{booktabs, makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcommand\mc[1]{\multicolumn{2}{c}{#1}}
% if you like to see page layout, remove before next two lines
%\usepackage{showframe} %
%\renewcommand*\ShowFrameColor{\color{red}}
\begin{document}
\begin{table}[htb]
\renewcommand\tabularxcolumn[1]{m{#1}}
\centering
\sffamily%
\setlength\aboverulesep{1ex}
\setlength\belowrulesep{1ex}
\renewcommand{\cellalign}{lc}
\begin{tabularx}{\linewidth}{ L L L}
\toprule[2pt]
Xxxxxx & Xxxxx & xxxxx xxxx xxxx x \\
\midrule[0.5pt]
\multirow{7}{=}{Xxxxx}
& Xxxxxx xxxxx & yyyyyy \\
& Xxxxxxxxxxxx & yyyyyy \\
& Xxxxxxxx & yyyyyy \\
& Yyyyxxxxxxxxxxxxx & yyyyyy \\
& Xxxxxxxxxxxxxxxxxx & yyyyyy \\
& Xxxxxxxxxxxxxxx & yyyyyy \\
\cmidrule{2-3}
& \mc{Zzzzzzz}\\
\midrule
Xxxxxxxxxxxxxxxx & \mc{xxxxxx} \\
Xxxxxxxxxxxxxxxxx & \mc{xxxxxx} \\
\bottomrule[2pt]%
\end{tabularx}%
\end{table}%
\end{document}