您想创建一个表格,其中两个单元格应水平合并。输出表格应如下所示:
我已经尝试过了
\begin{table}[t]\small
\centering
\caption{Technical Characteristics of Hyperspectral Imaging System.}
\begin{tabular}{|c|c|c|c|c|}
\hline
Patch Size& & CNN& & HOG\\
\hline
& Training & Testing & Training & Testing\\
\hline
500 x 500 & 99.43 & 94.72 & 83.28 & 74.34\\
\hline
\end{tabular}
\label{camera}
\end{table}
但它没有起作用
答案1
正如 @cfr 在评论中指出的那样,该\multicolumn
指令可用于跨列“合并”多个单元格。例如,
\multicolumn{2}{c}{Some text}
将字符串“Some text”居中放置在两列之间。
使用时\multicolumn
,请注意此指令完全取代了默认列属性。这意味着,如果所讨论的两列的默认属性包括右侧有垂直线边框,并且您希望合并的单元格右侧有垂直线边框,则需要编写
\multicolumn{2}{c|}{Some text}
在组合单元格的右侧添加垂直线。
您可能还想熟悉如何让表格看起来更适合读者。如果您想坚持使用大量垂直和水平规则,至少要稍微增加垂直间距,例如将其设置\extrarowheight
为非零长度。(2pt
通常就足够了。)或者,继续删除所有垂直规则,使用较少但间距适当的水平规则。您的读者几乎肯定会欣赏由此产生的开放和吸引人的“外观”——他们可能会通过实际查看内容来回报您的努力里面桌子...
下面的截图和代码说明了这些要点。
\documentclass{article}
\usepackage{array} % for \extrarowheight macro
\usepackage{booktabs} % for \toprule, \midrule, \cmidrule & \bottomrule macros
\begin{document}
\begin{table}[t]
\centering
\caption{Initial ``look''}
\label{camera:1}
\begin{tabular}{|c|c|c|c|c|}
\hline
Patch Size& & CNN& & HOG\\
\hline
& Training & Testing & Training & Testing\\
\hline
500 x 500 & 99.43 & 94.72 & 83.28 & 74.34\\
\hline
\end{tabular}
\bigskip
\caption{Two \texttt{\string\multicolumn} directives} \label{camera:2}
\begin{tabular}{|c|c|c|c|c|}
\hline
Patch Size & \multicolumn{2}{c|}{CNN} & \multicolumn{2}{c|}{HOG}\\
\hline
& Training & Testing & Training & Testing\\
\hline
500 x 500 & 99.43 & 94.72 & 83.28 & 74.34\\
\hline
\end{tabular}
\bigskip
\setlength\extrarowheight{2pt} % for a less-cramped look
\caption{A less-cramped look; ``$\times$'' rather than ``x''}
\label{camera:3}
\begin{tabular}{|c|c|c|c|c|}
\hline
Patch Size & \multicolumn{2}{c|}{CNN} & \multicolumn{2}{c|}{HOG}\\
\hline
& Training & Testing & Training & Testing\\
\hline
500 $\times$ 500 & 99.43 & 94.72 & 83.28 & 74.34\\
\hline
\end{tabular}
\bigskip
\setlength\extrarowheight{0pt} % reset to default value
\caption{A much more open look}
\label{camera:4}
\begin{tabular}{@{} ccccc @{}} % note: no vertical bars at all
\toprule % not \hline
Patch Size & \multicolumn{2}{c}{CNN} & \multicolumn{2}{c@{}}{HOG}\\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& Training & Testing & Training & Testing\\
\midrule % not \hline
500 $\times$ 500 & 99.43 & 94.72 & 83.28 & 74.34\\
\bottomrule % not \hline
\end{tabular}
\end{table}
\end{document}