请帮我画这张表格
| P1 | P2 |
| s1 | s2 |s3 | s4 | s5 | s6 | s7 | s8 | s9 | s10 |
这就是我尝试的方法,但我无法得到正确的线路
\begin{table}[h!]
\centering
\caption{HI}
\newcolumntype{L}{>{\centering\arraybackslash}m{1in}}
%\begin{small}
\resizebox{9cm}{!}
{
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
\hline
\cline{1-1} \multicolumn{5}{c|}{A} & \multicolumn{3}{c|}{ B}\\
\cline{2-5} \cline{6-8}
%\hline
h & N1 & M1 & Avg1 & Reqd.P & M2 & Avg2 & reqd.P & optimal P \\
\hline
1 & 5 & 2 & 4.75 & 1 & 3 & 4.50 & 1 & 1\\
\hline
2 & 13 & 6 & 12.34 & 2 & 7 & 11.7 & 2 & 2\\
\hline
\end{tabular}
}
%\end{small}
\end{table}
答案1
我会这样做,使用booktabs
(无垂直规则)和siunitx
(第 4 列和第 7 列的小数点对齐)。不确定您为什么使用\resizebox
,所以我删除了它:
\documentclass{article}
\usepackage{showframe}
\usepackage{siunitx}
\usepackage{array, booktabs, caption}
\begin{document}
\begin{table}[!h]
\centering\setlength\tabcolsep{4pt}
\caption{HI}\label{mytable}
\begin{tabular}{*{3}{c}S[table-format=2.2]cc S[table-format=2.2]cc}
\toprule
\multicolumn{5}{c}{A} & \multicolumn{3}{c}{ B}\tabularnewline
\cmidrule(lr){1-5}\cmidrule(lr){6-8}
h & N1 & M1 & {Avg1} & Reqd. P & M2 & {Avg2} & Reqd. P & Optimal P \tabularnewline
\midrule[\heavyrulewidth]
1 & 5 & 2 & 4.75 & 1 & 3 & 4.50 & 1 & 1\tabularnewline
2 & 13 & 6 & 12.34 & 2 & 7 & 11.7 & 2 & 2\tabularnewline
\bottomrule
\end{tabular}
\end{table}
\end{document}