# How to combine multiple rows with multiple columns with headings in one table?

I am struggling to create a table with three dimension to look up a fourth.

Consider the following binomial table as an example

##===##=================##===##
||   ||        p        ||   ||
|| n **-----+-----+-----** k ||
||   || .1  | .25 | .5  ||   ||
##===##=====*=====*=====##===##
||   || ... | ... | ... || 1 ||
||   **-----+-----+-----**---**
|| 3 || ... | ... | ... || 2 ||
||   **-----+-----+-----**---**
||   || ... | ... | ... || 3 ||
##===##=====*=====*==========##
||   || ... | ... | ... || 1 ||
||   **-----+-----+-----**---**
|| 4 || ... | ... | ... || 2 ||
||   **-----+-----+-----**---**
||   || ... | ... | ... || 3 ||
##===##=====*=====*==========##
||   || ... | ... | ... || 1 ||
||   **-----+-----+-----**---**
|| 5 || ... | ... | ... || 2 ||
||   **-----+-----+-----**---**
||   || ... | ... | ... || 3 ||
##===##=====*=====*=====##===##


Where * is a single line crossing a double line and ... are the corresponding b(n;p;k).

I am just asking for a convenient way to format a table like this, there is no need to calculate the binomial probabilities or something like that since this is just an example.

You could achieve the double line by using \hhline{#=#===#=#} as in

But if you zoom out you'll see some weird details as the one inside the red circle (but visible along the lines):

But as you would read somewhere else, I'd advise against the use of vertical rules to improve readability. Not to mention that you would have a much cleaner code.

So this is my suggestion for your table. It uses the booktabs package which makes for much better lines:

And the code:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{booktabs}

\pagestyle{empty}
\begin{document}
\begin{tabular}{ccccc}
\toprule
\multirow{2}{*}{n}  & \multicolumn{3}{c}{p} & \multirow{2}{*}{k} \\ \cmidrule{2-4}
& .1 & .25 & .5 & \\ \midrule
& \ldots & \ldots & \ldots & 1 \\ \cmidrule{2-4}
3   & \ldots & \ldots & \ldots & 2 \\ \cmidrule{2-4}
& \ldots & \ldots & \ldots & 3 \\ \midrule
& \ldots & \ldots & \ldots & 1 \\ \cmidrule{2-4}
4   & \ldots & \ldots & \ldots & 2 \\ \cmidrule{2-4}
& \ldots & \ldots & \ldots & 3 \\ \midrule
& \ldots & \ldots & \ldots & 1 \\ \cmidrule{2-4}
5   & \ldots & \ldots & \ldots & 2 \\ \cmidrule{2-4}
& \ldots & \ldots & \ldots & 3 \\ \bottomrule

\end{tabular}
\end{document}

• Since I do not always have 3 rows as in the example (my fault), I needed an additional \multirow{3}{*}{...} around the n values in the first column. While this works quite nice I noticed that the rules seem to be not included in the multirow heigth (the n and k in your header row are a little bit too high). With just one rule (like in your header row) this is not a big deal, but with multiple rows it looks weird. Do you have an easy solution or do you think this is worth another question? Commented Oct 25, 2013 at 14:48
• @sg-lecram Well, for the two rows, you could type \multirow{2}{*}[-2pt]{k} and the same for n... Not sure how to do the centering for multiple rows (I noticed that too) and to be honest, this is the first time I've noticed that. :P Commented Oct 25, 2013 at 15:12