[Tex/LaTex] How to combine multiple rows with multiple columns with headings in one table

multicolumnmultirowtables

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.

Best Answer

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

enter image description here

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

enter image description here

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:

enter image description here

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}