我在创建下表时遇到问题:
我编写了此代码,它创建了下表而不是上面的表。
\begin{center}
\begin{tabular}{| p{3cm}| p{3.5cm} |>{\columncolor[gray]{0.8}}p{2cm}|>{\columncolor[gray]{0.8}}p{2cm}| p{2cm}| p{2cm} | }
\hline
\multirow{2}{*}{Collection} & \multirow{2}{*}\Longstack{Number of relevant \newline documents based on \newline the relevance judgement \newline qrel file } & \multicolumn{2}{c|}{Number of relevant \newline documents retrieved \newline (context window size of 5)} & \multicolumn{2}{c|}{Number of relevant \newline documents retrieved \newline (context window size of 10)} \\
\cline{3-6}
{} & {} & {Negative\newline Sampling} & {Hierarchical \newline Softmax} & {Negative\newline Sampling} & {Hierarchical \newline Softmax}\\
\hline
Robust04 & 17,412 & 13,178 & 13,129 & 12,647 & 12,651 \\
\hline
ClueWeb09-B-1m & 212 & 156 & 130 & 157 & 148 \\
\hline
ClueWeb09-B-2m & 1,050 & 990 & 989 & 998 & 984 \\
\hline
ClueWeb09-B-5m & 1,666 & 1,459 & 1,458 & 1,471 & 1,436 \\
\hline
Pooled baseline & 6,390 & 6,196 & 6,085 & 6,024 & 5,964 \\
\hline
\end{tabular}
\captionof{table}{Impact of sampling strategies on retrieval effectiveness ($k_3$ and $D500$).} \label{tab:t7}
\end{center}
我该如何修复这个问题?
答案1
我将重点关注此表的设计工作:(a) 将数字与各自的小数点对齐,(b) 将五个数据列的内容居中,(c) 通过省略所有垂直线和大多数水平线使表格看起来更开放,以及 (d) 使标题材料具有更吸引人的视觉结构。我建议使用环境tabularx
,因为它提供了一种允许自动换行的单元格类型 ( X
)——无需手动插入换行符。下表试图实现这些目标。
% !TEX TS-program = pdflatex
\documentclass{article}
\usepackage[english]{babel}
\hyphenation{docu-ments}
\usepackage{tabularx,ragged2e,booktabs,siunitx}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\usepackage[letterpaper,margin=1in]{geometry} % set page parameters suitably
\begin{document}
\begin{table}[ht!]
\sisetup{table-format=5.0,
group-minimum-digits=4,
group-separator={,}}
\setlength\tabcolsep{3pt} % default value: 6pt
\begin{tabularx}{\textwidth}{@{} l *{5}{S} @{}}
\toprule
Collection
& \multicolumn{1}{>{\hsize=1.6\hsize}C}{%
Number of relevant documents based on the relevance judgement qrel file}
& \multicolumn{2}{>{\hsize=\dimexpr1.7\hsize+2\tabcolsep\relax}C}{%
Number of relevant documents retrieved (context window size of 5)}
& \multicolumn{2}{>{\hsize=\dimexpr1.7\hsize+2\tabcolsep\relax}C}{%
Number of relevant documents retrieved (context window size of~10} \\
\cmidrule(lr){3-4} \cmidrule(l){5-6}
& % ( 1.6+4*0.85=5, i.e., the number of columns of type "C")
& \multicolumn{1}{>{\hsize=0.85\hsize}C}{Negative Sampling}
& \multicolumn{1}{>{\hsize=0.85\hsize}C}{Hierarchical Softmax}
& \multicolumn{1}{>{\hsize=0.85\hsize}C}{Negative Sampling}
& \multicolumn{1}{>{\hsize=0.85\hsize}C@{}}{Hierarchical Softmax}\\
\midrule
Robust04 & 17412 & 13178 & 13129 & 12647 & 12651 \\
ClueWeb09-B-1m & 212 & 156 & 130 & 157 & 148 \\
ClueWeb09-B-2m & 1050 & 990 & 989 & 998 & 984 \\
ClueWeb09-B-5m & 1666 & 1459 & 1458 & 1471 & 1436 \\
Pooled baseline & 6390 & 6196 & 6085 & 6024 & 5964 \\
\bottomrule
\end{tabularx}
\caption{Impact of sampling strategies on retrieval effectiveness
($k_3$ and $D500$).}
\label{tab:t7}
\end{table}
\end{document}