Combination of multirows and multicolumns table [duplicate]

I need to create similar table using LaTeX:

I have tried to use tabular and \multicolumn, but every time I get something wrong.

Could someone help me?

\documentclass{article}
\begin{document}
\begin{tabular}{ | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | }
\hline
\  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  \\    \hline
\  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  \\   \hline
\  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  & \  \\ \hline
NAME & L &  &  & M &  &  & N &  &  & O &  &  & K &  &  \\ \hline
& L1 & L2 & L3 & M1 & M2 & M3 & N1 & N2 & N3 & O1 & O2 & O3 & K1 & K2 & K3 \\ \hline
A & 31 & 11 & 22 & 5 & 1 & 5 & 5 & 1 & 5 & 2 & 0 & 0 & 4 & 2 & 0 \\ \hline
B & 11 & 10 & 4 & 23 & 6 & NA & 8 & 0 & 2 & 1 & 0 & 1 & 1 & 1 & 1 \\ \hline
C & 7 & 4 & 2 & 3 & 1 & NA & 2 & 3 & 1 & 2 & 3 & 1 & 4 & 2 & 1 \\ \hline
D & 21 & 8 & 9 & 29 & 3 & 15 & 22 & 3 & 2 & 6 & 0 & 0 & 3 & 4 & 0 \\ \hline
\end{tabular}
\end{document}

-

marked as duplicate by Svend Tveskæg, Werner, Heiko Oberdiek, barbara beeton, JesseApr 25 '14 at 16:23

Check this page. Everything is explained. Take a special look at \cline, and \multirow. –  perror Apr 25 '14 at 15:32
There are a number of examples that use the \multicolumn and \multirow combination. Here are a few examples: Table with multiple merging; Formatting of Tables in LaTeX, using \multirow and \multicolumn together; Combine 4 cells in a table –  Werner Apr 25 '14 at 15:35

There is no need for multirow given your example. Instead, just a number of \multicolumns would do, with one \cline:

\documentclass{article}
\begin{document}
\begin{tabular}{ | *{16}{c|} }
\hline
& \multicolumn{3}{c|}{L} & \multicolumn{3}{c|}{M} & \multicolumn{3}{c|}{N} & \multicolumn{3}{c|}{O} & \multicolumn{3}{c|}{K} \\ \cline{2-16}
NAME & L1 & L2 & L3 & M1 & M2 & M3 & N1 & N2 & N3 & O1 & O2 & O3 & K1 & K2 & K3 \\ \hline
A   & 31 & 11 & 22 &  5 &  1 &  5 &  5 &  1 &  5 &  2 &  0 &  0 &  4 &  2 &  0 \\ \hline
B   & 11 & 10 &  4 & 23 &  6 & NA &  8 &  0 &  2 &  1 &  0 &  1 &  1 &  1 &  1 \\ \hline
C   &  7 &  4 &  2 &  3 &  1 & NA &  2 &  3 &  1 &  2 &  3 &  1 &  4 &  2 &  1 \\ \hline
D   & 21 &  8 &  9 & 29 &  3 & 15 & 22 &  3 &  2 &  6 &  0 &  0 &  3 &  4 &  0 \\ \hline
\end{tabular}
\end{document}


Note the use of the abbreviated column specification *{16}{c|}. This places 16 columns each of which have a c| specification (centered with a vertical rule to the right). It's easier to maintain than placing each of them individually.

Here is a booktabs version:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ *{16}{c} }
\toprule
& \multicolumn{3}{c}{L} & \multicolumn{3}{c}{M} & \multicolumn{3}{c}{N} & \multicolumn{3}{c}{O} & \multicolumn{3}{c}{K} \\
\cmidrule(lr){2-4}\cmidrule(lr){5-7}\cmidrule(lr){8-10}\cmidrule(lr){11-13}\cmidrule(lr){14-16}
NAME & L1 & L2 & L3 & M1 & M2 & M3 & N1 & N2 & N3 & O1 & O2 & O3 & K1 & K2 & K3 \\
\midrule
A   & 31 & 11 & 22 &  5 &  1 &  5 &  5 &  1 &  5 &  2 &  0 &  0 &  4 &  2 &  0 \\
B   & 11 & 10 &  4 & 23 &  6 & NA &  8 &  0 &  2 &  1 &  0 &  1 &  1 &  1 &  1 \\
C   &  7 &  4 &  2 &  3 &  1 & NA &  2 &  3 &  1 &  2 &  3 &  1 &  4 &  2 &  1 \\
D   & 21 &  8 &  9 & 29 &  3 & 15 & 22 &  3 &  2 &  6 &  0 &  0 &  3 &  4 &  0 \\
\bottomrule
\end{tabular}
\end{document}

-
It would be nicer with \multirow to center the NAME label in between the two columns... But, I agree with Werner, your example as you depicted it didn't need it. –  perror Apr 25 '14 at 15:54
If you have (or want to) use multirow, you can use \multirow{-2}*{NAME}, which will place NAME vertically centred in the 2 rows above (hence the negative). –  Werner Apr 25 '14 at 15:58