![如何编码此表](https://linux22.com/image/298704/%E5%A6%82%E4%BD%95%E7%BC%96%E7%A0%81%E6%AD%A4%E8%A1%A8.png)
我尝试生成此表,但我的代码有问题。我该如何更改代码以获得所需的输出?
\documentclass[11pt,a5paper]{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{ |l|l|l| }
\hline
\multicolumn{3}{ |c| }{x=0.5&x=0.6 & x=0.7} \\
\hline
MD &RM& MD\\ \hline
3& 8 & 7 \\
4 & 10& 8\\
5& 3& 9 \\
\\ \hline
\hline
\end{tabular}
\end{document}
答案1
你误用了\multicolumn
:
\documentclass[11pt,a5paper]{article}
\begin{document}
\begin{tabular}{ |*{6}{c|} }
\hline
\multicolumn{2}{ |c| }{$x=0.5$} &
\multicolumn{2}{ c| }{$x=0.6$} &
\multicolumn{2}{ c| }{$x=0.7$} \\
\hline
MD & RM& MD & RM & MD & RM \\
\hline
3 & 8 & 7 & 11 & 0 & 1 \\
4 & 10 & 8 & 12 & 4 & 2 \\
5 & 3 & 9 & 1 & 3 & 0 \\
\hline
\multicolumn{2}{ |c| }{$y=70$} &
\multicolumn{2}{ c| }{$z=50$} &
\multicolumn{2}{ c| }{$xy=10$} \\
\hline
\end{tabular}
\end{document}
请注意,这multirow
不是必需的(几乎不需要)。
使用不同的实现booktabs
\documentclass[11pt,a5paper]{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ *{6}{c} }
\toprule
\multicolumn{2}{ c }{$x=0.5$} &
\multicolumn{2}{ c }{$x=0.6$} &
\multicolumn{2}{ c }{$x=0.7$} \\
\cmidrule(lr){1-2}
\cmidrule(lr){3-4}
\cmidrule(lr){5-6}
MD & RM& MD & RM & MD & RM \\
\cmidrule(lr){1-2}
\cmidrule(lr){3-4}
\cmidrule(lr){5-6}
3& 8 & 7 & 11 & 0 & 1\\
4 & 10& 8 & 12 & 4 & 2\\
5& 3& 9 & 1 & 3 & 0\\
\cmidrule(lr){1-2}
\cmidrule(lr){3-4}
\cmidrule(lr){5-6}
\multicolumn{2}{ c }{$y=70$} &
\multicolumn{2}{ c }{$z=50$} &
\multicolumn{2}{ c }{$xy=10$} \\
\bottomrule
\end{tabular}
\end{document}
进一步改进siunitx
可以更好地放置数字:
\documentclass[11pt,a5paper]{article}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{tabular}{ *{6}{S[table-format=2.0]} } % two digits for the integral part, no decimals
\toprule
\multicolumn{2}{ c }{$x=0.5$} &
\multicolumn{2}{ c }{$x=0.6$} &
\multicolumn{2}{ c }{$x=0.7$} \\
\cmidrule(lr){1-2}
\cmidrule(lr){3-4}
\cmidrule(lr){5-6}
{MD} & {RM} & {MD} & {RM} & {MD} & {RM} \\
\cmidrule(lr){1-2}
\cmidrule(lr){3-4}
\cmidrule(lr){5-6}
3& 8 & 7 & 11 & 0 & 1\\
4 & 10& 8 & 12 & 4 & 2\\
5& 3& 9 & 1 & 3 & 0\\
\cmidrule(lr){1-2}
\cmidrule(lr){3-4}
\cmidrule(lr){5-6}
\multicolumn{2}{ c }{$y=70$} &
\multicolumn{2}{ c }{$z=50$} &
\multicolumn{2}{ c }{$xy=10$} \\
\bottomrule
\end{tabular}
\end{document}