我试图在表格上方添加标题,但没有成功。代码如下:
\begin{table}[b]
\centering
\begin{tabular}{|c|c|c|c|}
\cline{2-4}
\multicolumn{1}{c|}{}& &{CPU time}&\\
\cline{2-4}
\multicolumn{1}{c|}{} & Algorithm 1 & Algorithm 2 & Algorithm 3\\
\hline
$n=29$ & $0.001137$ & $0.000962$ & $0.000679$\\
\hline
$n=97$ & $0.020917$ & $0.008182$ & $0.005571$\\
\hline
$n=353$ & $0.699906$ & $0.067613$ & $0.054980$\\
\hline
$n=1345$ & $32.03852$ & $1.063334$ & $0.823744$\\
\hline
\end{tabular}
\caption{Caption}
\label{time}
\end{table}
如何更好地设置标题?谢谢!
我想要获得的是:
答案1
没有垂直线和对齐小数点分隔符的替代布局可以是
\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{table}[b]
\centering
\begin{tabular}{l S S S S }
\toprule
\multicolumn{1}{c}{} & \multicolumn{3}{c}{\large CPU Time} \\
& \multicolumn{1}{c}{Algorithm 1} & \multicolumn{1}{c}{Algorithm 2} & \multicolumn{1}{c}{Algorithm 3}\\
\midrule
$n=29$ & 0.001137 & 0.000962 & 0.000679 \\
\midrule
$n=97$ & 0.020917 & 0.008182 & 0.005571 \\
\midrule
$n=353$ & 0.699906 & 0.067613 & 0.054980 \\
\midrule
$n=1345$ & 32.03852 & 1.063334 & 0.823744 \\
\bottomrule
\end{tabular}
\caption{Caption\label{time}}
\end{table}
\end{document}
使用siunitx
和booktabs
包
答案2
好的,你可以这样做
\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{booktabs}
\begin{document}
\begin{table}[b]
\centering
\begin{tabular}{|c|c|c|c|}
\cline{2-4}
\multicolumn{1}{c}{} & \multicolumn{3}{|c|}{CPU time}\\
\cline{2-4}
\multicolumn{1}{c|}{} & Algorithm 1 & Algorithm 2 & Algorithm 3\\
\hline
$n=29$ & $0.001137$ & $0.000962$ & $0.000679$\\
\hline
$n=97$ & $0.020917$ & $0.008182$ & $0.005571$\\
\hline
$n=353$ & $0.699906$ & $0.067613$ & $0.054980$\\
\hline
$n=1345$ & $32.03852$ & $1.063334$ & $0.823744$\\
\hline
\end{tabular}
\caption{Caption}
\label{time}
\end{table}
\end{document}
但布局看起来很丑。避免在表格中使用垂直线。