Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

I need to create similar table using LaTeX:

enter image description here

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}
share|improve this question

marked as duplicate by Svend Tveskæg, Werner, Heiko Oberdiek, barbara beeton, Jesse Apr 25 at 16:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Check this page. Everything is explained. Take a special look at \cline, and \multirow. –  perror Apr 25 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 at 15:35

1 Answer 1

up vote 3 down vote accepted

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

enter image description here

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

enter image description here

\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}
share|improve this answer
1  
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 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 at 15:58

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