我尝试使用 \multirow 创建下面的表格,但失败了。在项目下方添加“单位”导致表格创建变得困难。有人能帮我吗?
答案1
我不认为使用\multirow
可以改善标题单元格的外观——事实上恰恰相反。第一组和第二组三列之间的大间隙似乎太大了;您可以通过修剪 s 以\cmidrule
留下适度的视觉间隙来获得更好的整体效果。最后,由于数据是数字,您可能需要考虑使用S
列类型(由包提供siunitx
)而不是基本c
列类型。
\documentclass{book}
\usepackage{booktabs,caption,siunitx}
\begin{document}
\begin{table}
\centering
\caption{Comparison of Groups A and B}\label{AB}
\begin{tabular}{@{}l*{7}{S[table-format=1.3]}@{}}
\toprule
No. & A & \multicolumn{3}{c}{Group A} &\multicolumn{3}{c@{}}{Group B}\\
\cmidrule(lr){3-5}
\cmidrule(l){6-8}
&&A&B&C&A&B&C\\
&{(unit)}&{(unit)}&&{(unit)}&{(unit)}&&{(unit)}\\
\midrule
1 & 0.751 & 0.498 & 0.706 & 0.823 & 0.439 & 0.490 & 0.276\\
2 & 0.255 & 0.960 & 0.032 & 0.695 & 0.382 & 0.446 & 0.680\\
3 & 0.506 & 0.340 & 0.277 & 0.317 & 0.766 & 0.646 & 0.655\\
4 & 0.699 & 0.585 & 0.046 & 0.950 & 0.795 & 0.709 & 0.163\\
5 & 0.891 & 0.224 & 0.097 & 0.034 & 0.187 & 0.755 & 0.119\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
表格构造:
代码:
\documentclass[table]{book}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{caption}
\usepackage{listings}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular*}{0.90\textwidth}{@{\extracolsep{\fill}}rrrrrrrr}
\hline \hline
\multirow{4}{*}{No} & \multirow{4}{*}{A} & \multicolumn{3}{c}{Group A} & \multicolumn{3}{c}{Group B}\\
& \multirow{4}{*}{(unit)}&\multicolumn{3}{c}{-------------------------------} &\multicolumn{3}{c}{-------------------------------} \\
& & A & \quad \quad B & C & A &\quad \quad B &C \\
& & (unit) & &(unit) & (unit) & &(unit)\\
\hline
1 & 0.751 & 0.498 & 0.706 & 0.823 & 0.439 & 0.490 & 0.276 \\
2 & 0.255 & 0.960 & 0.032 & 0.695 & 0.382 & 0.446 & 0.680 \\
3& 0.506 & 0.340 & 0.277 & 0.317 & 0.766 & 0.646 & 0.655 \\
4& 0.699 & 0.585 & 0.046 & 0.950 & 0.795 & 0.709 &0.163 \\
5 & 0.891 & 0.224 & 0.097 & 0.034 & 0.187 & 0.755 & 0.119\\
\hline \hline
\end{tabular*}
\caption{Comparison of Group A and B}
\label{tab:compr}
\end{table}
\end{document}
结果
答案3
\documentclass[table]{book}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{caption}
\begin{document}
\begin{table}[H]
\centering
\caption{Comparison of Group A and B}\label{AB}
\begin{tabular}{ccccccccc}
\toprule
\multirow{3}[4]{*}{No.} & & \multicolumn{3}{c}{Group A} & &\multicolumn{3}{c}{Group B}\\
\cmidrule(r){3-5}
\cmidrule(r){7-9}
&A&A&\multirow{2}[4]{*}{B}&C&&A&\multirow{2}[4]{*}{B}&C\\
&(unit)&(unit)&&(unit)&&(unit)&&(unit)\\
\midrule
1 & 0.751 & 0.498 & 0.706 & 0.823 && 0.439 & 0.490 & 0.276 \\
2 & 0.255 & 0.960 & 0.032 & 0.695 && 0.382 & 0.446 & 0.680 \\
3 & 0.506 & 0.340 & 0.277 & 0.317 && 0.766 & 0.646 & 0.655 \\
4 & 0.699 & 0.585 & 0.046 & 0.950 && 0.795 & 0.709 &0.163 \\
5 & 0.891 & 0.224 & 0.097 & 0.034 && 0.187 & 0.755 & 0.119\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案4
makecell
对前几行采用不同的对齐方式、自动对行进行编号以及使用或包稍微简化代码stackengine
(无多行):
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{booktabs, caption, siunitx}
\usepackage{makecell}
\renewcommand\theadalign{tc}
\usepackage{tabstackengine}
\setstackEOL{\\}
\newcounter{rowno}
\newcommand\emptycell{\multicolumn{1}{c}{}}
\providecommand*\No{N\textsuperscript{\kern0.06em\underline{\kern-0.06em o\kern-0.068em}}}
\begin{document}
With \texttt{makecell}:
\begin{table}[!h]
\centering
\setcounter{rowno}{0}
\caption{Comparison of Groups A and B}\label{AB}
\begin{tabular}{>{\refstepcounter{rowno}\,\therowno}c*{7}{S[table-format=1.3]}}%{}
\toprule
\emptycell & & \multicolumn{3}{c}{Group A} &\multicolumn{3}{c@{}}{Group B}\\
\cmidrule(lr){3-5} \cmidrule(lr){6-8}
\multicolumn{1}{c}{\thead{\\\No}} & {\thead{A\\}}& {\thead{A\\(unit)}} &{ \thead{B\\}} &{\thead{C\\(unit)}} & {\thead{A\\(unit)}}& {\thead{B}} & {\thead{C\\(unit)}}\\
\cmidrule[\lightrulewidth](lr){1-8}
\addlinespace[1.2ex]
& 0.751 & 0.498 & 0.706 & 0.823 & 0.439 & 0.490 & 0.276\\
& 0.255 & 0.960 & 0.032 & 0.695 & 0.382 & 0.446 & 0.680\\
& 0.506 & 0.340 & 0.277 & 0.317 & 0.766 & 0.646 & 0.655\\
& 0.699 & 0.585 & 0.046 & 0.950 & 0.795 & 0.709 & 0.163\\
& 0.891 & 0.224 & 0.097 & 0.034 & 0.187 & 0.755 & 0.119\\
\bottomrule
\end{tabular}
\end{table}
\vskip 1cm
With \texttt{stackengine}:
\begin{table}[!h]
\centering
\setcounter{rowno}{0}
\caption{Comparison of Groups A and B}\label{AB}
\begin{tabular}{@{}>{\refstepcounter{rowno}\,\therowno}c*{7}{c}}%{}S[table-format=1.3]
\toprule
\emptycell & & \multicolumn{3}{c}{Group A} &\multicolumn{3}{c@{}}{Group B}\\
\cmidrule(lr){3-5} \cmidrule(lr){6-8}
\multicolumn{1}{c}{\stackunder{}{\No}} & {A} & {\stackunder{A}{(unit)}} & {B} &
{\stackunder{C}{(unit)}} & {\stackunder{A}{(unit)}}& {B} & {\stackunder{C}{(unit)}}\\
\addlinespace
\cmidrule[\lightrulewidth](lr){1-8}
\addlinespace[1.2ex]
& 0.751 & 0.498 & 0.706 & 0.823 & 0.439 & 0.490 & 0.276\\
& 0.255 & 0.960 & 0.032 & 0.695 & 0.382 & 0.446 & 0.680\\
& 0.506 & 0.340 & 0.277 & 0.317 & 0.766 & 0.646 & 0.655\\
& 0.699 & 0.585 & 0.046 & 0.950 & 0.795 & 0.709 & 0.163\\
& 0.891 & 0.224 & 0.097 & 0.034 & 0.187 & 0.755 & 0.119\\
\bottomrule
\end{tabular}
\end{table}
\end{document}