大家好,我是 LaTeX 的新手,我制作的表格中的间距有点小问题。
\documentclass[10pt]{article}
\usepackage[a4paper, total={7in, 10in}]{geometry}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{multirow}
\begin{document}
\begin{table}[h]
\centering
\begin{tabularx}{.7\textwidth}{@{}ccccc@{}}
\toprule
& \cr{\bfseries Number of heaters}
&\multicolumn{2}{c}{\bfseries Method 1}
&\multicolumn{2}{c}{\bfseries Method 2}
\\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
&Power/W
&Efficency/\%
&Power/W
&Efficency/\%
\\
\midrule
1 & 0.123 & 0.37 & 0.12 & 0.36 \\
2 & 0.250 & 0.39 & 0.21 & 0.36\\
3 & 0.345 & 0.36 & 0.35 & 0.34\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
如您所见,右侧有一些额外的间距,顶部也有一些额外的间距。如果有人能帮我移除这些间距,我将不胜感激。另外还有一个问题,有人知道如何将“加热器数量”与功率和效率对齐,而不是方法。提前谢谢!
答案1
\documentclass[10pt]{article}
\usepackage[a4paper, total={7in, 10in}]{geometry}
\usepackage{booktabs}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{@{}ccccc@{}}
\toprule
&\multicolumn{2}{c}{\bfseries Method 1}
&\multicolumn{2}{c}{\bfseries Method 2}
\\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
\bfseries Number of heaters
& Power/W & Efficency/\%
& Power/W & Efficency/\%
\\
\midrule
1 & 0.123 & 0.37 & 0.12 & 0.36 \\
2 & 0.250 & 0.39 & 0.21 & 0.36\\
3 & 0.345 & 0.36 & 0.35 & 0.34\\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[h]
\centering
\begin{tabular*}{.7\textwidth}{@{\extracolsep{\fill}}ccccc@{}}
\toprule
&\multicolumn{2}{c}{\bfseries Method 1}
&\multicolumn{2}{c}{\bfseries Method 2}
\\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
\bfseries Number of heaters
& Power/W & Efficency/\%
& Power/W & Efficency/\%
\\
\midrule
1 & 0.123 & 0.37 & 0.12 & 0.36 \\
2 & 0.250 & 0.39 & 0.21 & 0.36\\
3 & 0.345 & 0.36 & 0.35 & 0.34\\
\bottomrule
\end{tabular*}
\end{table}
\end{document}