0

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.

1 Answer 1

1

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}
2
  • 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?
    – mschilli
    Commented Oct 25, 2013 at 14:48
  • 1
    @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
    – Alenanno
    Commented Oct 25, 2013 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .