29

I'm trying to create a table in Latex but without success. I tried different solutions but no one solves my problem. I would like create a table like the picture below:

enter image description here

Can anyone show how to do this in Latex please?

MattAllegro
  • 6,455
  • 5
  • 45
  • 52
Stefano C.
  • 1,033
  • 3
  • 13
  • 17
  • 5
    Be careful with tables. Don't imprison your data in a grid of cells. [Data looks better naked](http://darkhorseanalytics.com/blog/data-looks-better-naked/). Also see Tufte's [concept of presenting tabular data.](http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0000Jr) – Roland Smith Aug 29 '15 at 23:44
  • In the comunity http://tex.stackexchange.com you can search for more examples. :-) – Carmoreno Nov 02 '16 at 04:05

2 Answers2

51

One first sketch may be the following:

\documentclass{article}
\usepackage{multirow}

\begin{document}

\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multirow{3}{*}{A} & \multicolumn{2}{c|}{User B} & %
    \multicolumn{2}{c|}{User C} & \multirow{3}{*}{D}\\
\cline{2-5}
 & \multicolumn{2}{c|}{Value} & \multicolumn{2}{c|}{Value} & \\
\cline{2-5}
 & B1 & B2 & C1 & C2 & \\
\hline
 & & & & & \\
\hline
 & & & & & \\
\hline
% etc. ...
\end{tabular}

\end{document}

It produces:

screenshot of output

Addendum:

\documentclass{article}
\usepackage{multirow}

\begin{document}

{\sffamily %
\begin{tabular}{|c|c|c|c|c|c|c|}% seven columns now, not six...
\hline
\multirow{3}{*}{A} & \multicolumn{2}{c|}{User B} & \multirow{3}{*}{X} & %
    \multicolumn{2}{c|}{User C} & \multirow{3}{*}{D}\\
\cline{2-3}\cline{5-6}
 & \multicolumn{2}{c|}{Value} & & \multicolumn{2}{c|}{Value} & \\
\cline{2-3}\cline{5-6}
 & B1 & B2 & & C1 & C2 & \\
\hline
 & & & & & & \\
\hline
 & & & & & & \\
\hline
% etc. ...
\end{tabular}
}%

\end{document}

produces:

enter image description here

Please, critically check all the differences between the original code and this latter.

Don't forget that several LaTeX packages can help you improving style, dimensions and spacing of your table: among these, I advise you to have a look at bigstrut.

Also:

\documentclass{article}
\usepackage{multirow}

\begin{document}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multirow{3}{*}{A} & \multirow{3}{*}{X} & \multicolumn{2}{c|}{User B} & \multicolumn{2}{c|}{User C} & \multirow{3}{*}{D}\\
\cline{3-6}
 & & \multicolumn{2}{c|}{Value} & \multicolumn{2}{c|}{Value} & \\
\cline{3-6}
 & & B1 & B2 & C1 & C2 & \\
\hline
 & & & & & & \\
\hline
\end{tabular}

\end{document}

You should now be able to operate on your own further changes to the model of table.

MattAllegro
  • 6,455
  • 5
  • 45
  • 52
2

Check out the multirow package:

http://texblog.org/2012/12/21/multi-column-and-multi-row-cells-in-latex-tables/

You have to include the library:

%multi-column
\multicolumn{number cols}{align}{text} % align: l,c,r

%multi-row
\usepackage{multirow}

\multirow{number rows}{width}{text}

Then it looks like this:

\documentclass[11pt]{article}
\usepackage{multirow}
\begin{document}

\begin{table}[ht]
\caption{Multi-column and multi-row table}
\begin{center}
\begin{tabular}{ccc}
    \hline
    \multicolumn{2}{c}{\multirow{2}{*}{Multi-col-row}}&X\\
    \multicolumn{2}{c}{}&X\\
    \hline
    X&X&X\\
    \hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

\end{document}

note: code examples from the link provided

MattAllegro
  • 6,455
  • 5
  • 45
  • 52
Brendan W
  • 3,303
  • 3
  • 18
  • 37