# How to make table with different columns per row?

I am trying to put the following table in Sharelatex:

I get how to make basic tables, but tables like the one above I find hard as the columns differ for certain rows. This is de code I have until now:

\begin{table}[h]
\begin{tabular}{|m{4cm}|m{4cm}|m{4cm}|m{4cm}|m{4cm}|m{4cm}}
\hline
\multicolumn{4}{|c|}{Display Format} \\
\hline
&High information-density & Low information-density & \\
\hline
\end{tabular}
\caption{Number of respondents per treatment}
\label{table:3}
\end{table}


However this is not providing me with the table I want and I am really stuck here. Can someone please help me with this one?

• What is your problem, exactly? – Bernard Aug 12 '16 at 21:33
• I don't know how to get the columns like in the example? – Lana Aug 12 '16 at 21:36
• Use the c specifiers, instead of m{4cm} (which will probably make your table too wide unless you're using something like A3paper. So it should begin with \begin{tabular}{ccccc}. For \multicolumn, you seem to know how to do. – Bernard Aug 12 '16 at 21:41
• Thanx for the tip! – Lana Aug 13 '16 at 13:37

Try this:

\documentclass{article}
\usepackage{sans}
\renewcommand{\arraystretch}{1.3}
\begin{document}
\begin{table}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
& \multicolumn{4}{|c|}{Display Format}& \\ \cline{2-5}
&\multicolumn{2}{|c|}{High information density}& \multicolumn{2}{|c|}{Low information density} &\\ \hline
Cookie type & Noticeable& Non-noticeable& Noticeable& Non-noticeable& Total \\ \hline
Total& 48&39&50&40&177\\ \hline

\end{tabular}
\caption{Number of respondants for treatment}
\end{table}
\end{document}


and image of table obtained by above code:

• Thanx a lot for your help! – Lana Aug 13 '16 at 5:59
• Instead \multicolumn{4}{|c|}{...} and \multicolumn{2}{|c|}{...} is better \multicolumn{4}{c|}{...} and \multicolumn{2}{c|}{...} respectively. Also columns spanned by multi columns haven't equal width. – Zarko Aug 13 '16 at 6:44

Your table is going to be very huge ... 24 cm wide :)- See if the following is what you looking for:

\documentclass{article}
\usepackage{array}

\begin{document}
\begin{table}[h]
\renewcommand\arraystretch{1.3}
\begin{tabular}{|l | *{4}{>{\centering}p{2cm}|}c|}
%{|m{4cm}|m{4cm}|m{4cm}|m{4cm}|m{4cm}|m{4cm}}
\hline
& \multicolumn{4}{c|}{Display Format}
&                                                   \\
\hline
& \multicolumn{2}{c|}{High information-density}
& \multicolumn{2}{c|}{Low information-density}
&   Total                                       \\
\hline
& 29    &   17  &   27  &   20  &   93                  \\
\hline
\end{tabular}
\caption{Number of respondents per treatment}
\label{table:3}
\end{table}
\end{document}


• Thanx so much for your help! – Lana Aug 13 '16 at 5:59
• Yes I always try all the suggested solutions I get from users here and just accept the one that is closest to what I need. I hope I answered your question – Lana Aug 13 '16 at 13:36

The following code produces your table. Use \multicolumn for spanning several columns. If the four center columns don't have to be of equal width, you don't need the array package and the new column type C; just use type c.

\documentclass[border=2pt]{standalone}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\renewcommand\familydefault{\sfdefault}
\begin{document}
{\def\arraystretch{1.2}%
\begin{tabular}{|c|C{2.3cm}|C{2.3cm}|C{2.3cm}|C{2.3cm}|c|}
\hline
&\multicolumn{4}{c|}{Display Format}{}&\\
\cline{2-5}
&\multicolumn{2}{c|}{High information density}&\multicolumn{2}{c|}{Low information density}&\\
\hline
Cookie Type & Noticeable & Non-noticeable & Noticeable & Non-noticeable & Total \\
\hline
1st party cookies     & 29 & 17 & 27 & 20 &  93 \\
\hline
1st/3rd party cookies & 19 & 22 & 23 & 20 &  84 \\
\hline
Total                 & 48 & 39 & 50 & 40 & 177 \\
\hline
\end{tabular}}
\end{document}