我写了以下代码:
\begin{table}
%\centering
\caption{Performance of Mesh Topology.}
\label{tab:meshperformance}
\begin{tabular}{|l|l|l|l|l|l|l||l||l|}
\hline
\multirow{2}{*}{Mesh Topology} &
\multicolumn{2}{c|}{TH(Kbps)} &
\multicolumn{2}{c|}{Energy(J)} &
\multicolumn{2}{c|}{Delay(ms)} &
\multicolumn{2}{c|}{PDR (\%)} \\ \midrule
& MD/MA, & MD/MA, & MD/MA, & MD/MA, & MD/MA, & MD/MA, & MD/MA, & MD/MA, \\
&T=1 & T=5 & T=1 & T=5 & T=1 & T=5 &T=1 &T=5 \\ \midrule
With Fusion & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% \\
\hline
Without Fusion & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 2.1\% & 2.1\% \\
\hline
%D3 & 5.5\% & 5.5\% & 5.5\% & 5.5\% & 5.5\% & 5.5\% & 2.1\% & 2.1\% \\
\hline
\end{tabular}
\end{table}
答案1
包中的线条booktabs
与垂直线不兼容,因此您在输出中观察到交叉点周围的小间隙。如果您想使用垂直和水平线,请将线条替换booktabs
为\hline
。在列规范中使用||
将导致双垂直线。如果您想要单垂直线,请改用|
。最后,命令的位置\multirow
与预期输出的图像不匹配。我也在以下 MWE 中更正了这一点。
由于您的表格非常宽,因此不太可能适合整个页面,因此我还添加了第二个示例,该示例的布局不同booktabs
(没有垂直线),siunitx
列标题中的单位和列中数字的对齐方式也得到了改进。我还尝试删除重复的信息。
\documentclass{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}
%\centering
\caption{Performance of Mesh Topology.}
\label{tab:meshperformance}
\begin{tabular}{|p{1.5cm}|l|l|l|l|l|l|l|l|}
\hline
Mesh Topology &
\multicolumn{2}{c|}{TH(Kbps)} &
\multicolumn{2}{c|}{Energy(J)} &
\multicolumn{2}{c|}{Delay(ms)} &
\multicolumn{2}{c|}{PDR (\%)} \\ \hline
\multirow[t]{3}{=}{With\newline Fusion} & MD/MA, & MD/MA, & MD/MA, & MD/MA, & MD/MA, & MD/MA, & MD/MA, & MD/MA, \\
&T=1 & T=5 & T=1 & T=5 & T=1 & T=5 &T=1 &T=5 \\ \cline{2-9}
& 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% \\
\hline
Without Fusion & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 2.1\% & 2.1\% \\
\hline
\end{tabular}
\end{table}
\begin{table}
\centering
\caption{Performance of Mesh Topology.}
\label{tab:meshperformance}
\begin{tabular}{l*{8}{S[table-format=2.1]}}
\toprule
Mesh Topology &
\multicolumn{2}{c}{TH (Kbps)} &
\multicolumn{2}{c}{Energy (\si{\joule})} &
\multicolumn{2}{c}{Delay (\si{\milli\second})} &
\multicolumn{2}{c}{PDR (\%)} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(lr){8-9}
MD/MA: & {T=1} & {T=5} & {T=1} & {T=5} & {T=1} & {T=5} & {T=1} & {T=5} \\
With Fusion (\%) & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 \\
Without Fusion (\%) & 11.6 & 11.6 & 11.6 & 11.6 & 11.6 & 11.6 & 2.1 & 2.1 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
宽度过大主要是由于重复的 MD/MA,可以将其减少到每对列一个。此外,通过在标题中指定一个 % 符号,可以避免所有 % 符号。
该\splitcell*
命令会创建一个没有深度的拆分单元;在这种情况下并不是真正需要的,但它在不同情况下会派上用场。
您应该可以将其做成笼式桌子,但我不推荐这样做。
\documentclass{article}
\usepackage{amsmath,siunitx,booktabs}
\usepackage{newtxtext,newtxmath}
\NewDocumentCommand{\splitcell}{sO{t}mm}{%
\IfBooleanTF{#1}
{\smash[b]{\makesplitcell{#2}{#3}{#4}}}
{\makesplitcell{#2}{#3}{#4}}%
}
\NewDocumentCommand{\makesplitcell}{mmm}{%
\begin{tabular}[#1]{@{}#2@{}}#3\end{tabular}%
}
\begin{document}
\begin{table}[htp]
\caption{Performance of Mesh Topology.}
\label{tab:meshperformance}
\begin{tabular}{
@{}
l
*{6}{S[table-format=2.1]}
*{2}{S[table-format=1.1]}
@{}
}
\toprule
\splitcell*{c}{Mesh \\ Topology} &
\multicolumn{2}{c}{\splitcell{c}{Throughput \\ (Kbps)}} &
\multicolumn{2}{c}{\splitcell{c}{Energy \\ (J)}} &
\multicolumn{2}{c}{\splitcell{c}{Delay \\ (ms)}} &
\multicolumn{2}{c}{\splitcell{c}{PDR \\ (\%)}} \\
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}
\cmidrule(lr){6-7}
\cmidrule(l){8-9}
& \multicolumn{2}{c}{MD/MA (\%)}
& \multicolumn{2}{c}{MD/MA (\%)}
& \multicolumn{2}{c}{MD/MA (\%)}
& \multicolumn{2}{c}{MD/MA (\%)} \\
\midrule
& {$T=1$} & {$T=5$} & {$T=1$} & {$T=5$} & {$T=1$} & {$T=5$} & {$T=1$} & {$T=5$} \\
\cmidrule(lr){2-2} \cmidrule(lr){3-3}
\cmidrule(lr){4-4} \cmidrule(lr){5-5}
\cmidrule(lr){6-6} \cmidrule(lr){7-7}
\cmidrule(lr){8-8} \cmidrule(lr){9-9}
With Fusion & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 \\
\addlinespace
Without Fusion & 11.6 & 11.6 & 11.6 & 11.6 & 11.6 & 11.6 & 2.1 & 2.1 \\
\addlinespace
D3 & 5.5 & 5.5 & 5.5 & 5.5 & 5.5 & 5.5 & 2.1 & 2.1 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
通过使用makecell
和siunitx
包:
\documentclass{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{booktabs, makecell, multirow}
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c|}{#2}}
\NewExpandableDocumentCommand\mcmc{O{1}m}
{\multicolumn{#1}{c|}{\makecell{#2}}}
\usepackage{siunitx}
\begin{document}
\begin{table}
\caption{Performance of Mesh Topology.}
\label{tab:meshperformance}
\centering
\setlength\tabcolsep{3pt}
\setcellgapes{3pt}
\makegapedcells
\begin{tabular}{|r |*{8}{S[table-format=2.1,
table-space-text-post={\,\%}]<{\,\%}|}
}
\Xhline{1.2pt}
\makecell{Mesh\\ Topology}
& \mcc[2]{TH (kbps)}
& \mcc[2]{Energy (\si{\joule})}
& \mcc[2]{TH (kbps)}
& \mcc[2]{PDR (\%)} \\
\Xhline{0.8pt}
MD/MA
& \mcc{$T=1$}
& \mcc{$T=5$}
& \mcc{$T=1$}
& \mcc{$T=5$}
& \mcc{$T=1$}
& \mcc{$T=5$}
& \mcc{$T=1$}
& \mcc{$T=5$} \\
\hline
With Fusion
& 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 \cr
\hline
Without Fusion
& 11.6 & 11.6 & 11.6 & 11.6 & 11.6 & 11.6 & 2.1 & 2.1 \cr
\Xhline{1.2pt}
\end{tabular}
\end{table}
\end{document}