我正在处理一张桌子,代码是:
\begin{table}[t!]
\small
\centering
\resizebox{0.45\textwidth}{!}{%
\begin{tabular}{@{}l|r@{ }r@{ }|r@{ }r@{ }|rrr@{ }}
\toprule
{} & \multicolumn{2}{c|}{\bf Without
Context} & \multicolumn{2}{c|}{\bf Wiki} & \multicolumn{2}{c}{\bf Wiki 2}\\
\midrule
\bf Model & \multicolumn{1}{c}{\bf Test} & \multicolumn{1}{c|}{\bf Dev} & \multicolumn{1}{c}{\bf Test} & \multicolumn{1}{c|}{\bf Dev} & \multicolumn{1}{c}{\bf Test} & \multicolumn{1}{c}{\bf Dev}\\
\midrule
Albanian & 565 & 755 & 1,194 & 311 & 1,194 & 311\\
Arabic & 1,194 & 562 & 1,194 & 1,194 & 1,194 & 311\\
Bulgarian & 1,100 & 1,472 & 2,344 & 593 & 1,194 & 311\\
\bottomrule
\end{tabular}
}
\caption{Number of examples in the data splits based on the experimental setup.
}
\label{tab:datasplits}
\end{table}
看起来像这样:
但可以看到,在 dev 设置中,值和 Dev 名称不一致。如何让它们对齐?
答案1
表格列右对齐,但 Dev 居中对齐,因此对齐错误
\multicolumn{1}{c|}{\bf Dev} needs to be \multicolumn{1}{r|}{\bf Dev}
删除@{}
Test 和 Dev 之间的代码行中使用的列空间
\begin{tabular}{@{}l@{}r@{}r@{}r@{}r@{}|rrr@{}}
正如 David Carlisle 在评论中正确指出的那样 - 应该避免使用垂直线,否则您会注意到间隙,因为您在booktabs
包中使用了 toprule/midrule
答案2
我将通过删除所有垂直规则、所有\bf
语句、所有\multicolumn{1}{c}{...}
包装器和\resizebox
指令来简化和精简表格的外观。我还将“Without”缩写为“w/o”。
\documentclass{article} % select a suitable document class
\usepackage{booktabs}
\begin{document}
\begin{table}[t!]
\small
\centering
\begin{tabular}{@{} l rrrrrr @{}}
\toprule
{} & \multicolumn{2}{c}{w/o Context}
& \multicolumn{2}{c}{Wiki}
& \multicolumn{2}{c@{}}{Wiki 2}\\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7}
Model & Test & Dev & Test & Dev & Test & Dev \\
\midrule
Albanian & 565 & 755 & 1,194 & 311 & 1,194 & 311\\
Arabic & 1,194 & 562 & 1,194 & 1,194 & 1,194 & 311\\
Bulgarian & 1,100 & 1,472 & 2,344 & 593 & 1,194 & 311\\
\bottomrule
\end{tabular}
\caption{Number of examples in the data splits based on the experimental setup.}
\label{tab:datasplits}
\end{table}
\end{document}