5

I tried to produce this table but I have problem with my code. How can I change my code to obtain the desired output?

\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}

enter image description here

  • 2
    Garry, you could consider going through your questions and accept the best answer to each (if it has solved your problem of course), this will mark the question as solved, and award some points to the both answerer and yourself. – Torbjørn T. Sep 28 '14 at 12:51
7

You're misusing \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}

enter image description here

Note that multirow is not needed (it is almost never).

A different realization using 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}

enter image description here

A further refinement with siunitx that allows better placement of numbers:

\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}

enter image description here

  • @Garry I added two different versions; avoid vertical rules. – egreg Sep 28 '14 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.