# \toprule and p{} in tabular

In my table, in order to have texts centered in each cell, I am using

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}


and instead of a simple p{1.5cm}, I am using

 >{\centering\arraybackslash}p{1.5cm}


I am also using \toprule, \midrule, and \bottomrule along with \usepackage{booktabs}.

My code is the following:

\documentclass[12pt]{article}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{| >{\centering\arraybackslash}p{1.5cm} | >{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm} |  >{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm} |>{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm}|}
\toprule
\multirow{2}{*}{} & \multicolumn{4}{c|}{Payoffs} &  \multicolumn{4}{c}{ROR} \\
\cline{2-9}
& $\theta =1$ & $\theta =2$ & $E(P)$ & $\sigma(P)$ & $\theta =1$ & $\theta =2$ & $E(r)$ & $\sigma(r)$ \\
\midrule
Asset 1 & 110 & 95 &   &   &   &   &   &   \\
Asset 2 & 105 & 90 &   &   &   &   &   &   \\
Asset 3 & 120 & 90 &   &   &   &   &   &   \\
\bottomrule
\end{tabular}
\end{table}

\end{document}


And my result looks very strange like this:

First, the far right vertical line is short; the first row is not closed on the right.

Second, all the vertical lines are cut.

Any thoughts?

• \toprule, \midrule and \bottomrule work under the assumption that no vertical rule is used. – egreg Feb 4 '16 at 0:30
• why have you defined P to be >{\centering\arraybackslash}p but then used the long form >{\centering\arraybackslash}p rather than P ? – David Carlisle Feb 4 '16 at 0:42
• The lack of vertical bar is because you used \multicolumn{4}{c}{ROR} but wanted \multicolumn{4}{c|}{ROR} however using vertical lines and booktabs doesn't work by design (see the booktabs doc for a tirade against the evils of vertical rules in tables:-) – David Carlisle Feb 4 '16 at 0:44

The vertical rule on the right is not short, it's missing, because you've used

\multicolumn{4}{c}{ROR}


\multicolumn{4}{c|}{ROR}


However, instead of adding the vertical rules, follow the guidelines suggested by booktabs (since you're using it anyway):

You will not go far wrong if you remember two simple guidelines at all times:

1. Never, ever use vertical rules.
2. Never use double rules.

\documentclass{article}

\usepackage{booktabs,array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}

\begin{tabular}{ P{15mm} *{8}{P{12mm}} }
\toprule
& \multicolumn{4}{c}{Payoffs} &  \multicolumn{4}{c}{ROR} \\
\cmidrule(lr){2-5}\cmidrule(lr){6-9}
& $\theta = 1$ & $\theta = 2$ & $E(P)$ & $\sigma(P)$ & $\theta = 1$ & $\theta = 2$ & $E(r)$ & $\sigma(r)$ \\
\midrule
Asset 1 & 110 & 95 &   &   &   &   &   &   \\
Asset 2 & 105 & 90 &   &   &   &   &   &   \\
Asset 3 & 120 & 90 &   &   &   &   &   &   \\
\bottomrule
\end{tabular}

\end{document}


The columnar stacking of values promotes visual alignment making the use of vertical rules somewhat obsolete.

• @Zarko: Agreed. – Werner Feb 4 '16 at 1:20

You can't use booktabs rules with vertical rules, because booktabs adds some vertical padding around its horizontal rules. For the same reason, one has problems trying to use colours in table cells with booktabs.

You can replace booktabs with boldlines, which allows for variable width rules in tables, in order to emulate the different kinds of rules of booktabs. However, in the opinion of many, your table will look nicer if you use only horizontal rules.

I give in the following code an example of both solutions. Note you don't need to use \multirow for empty cells.

\documentclass[12pt]{article}

\usepackage{array, boldline}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{booktabs}

\begin{document}

\begin{table}[!h]
\centering\renewcommand\arraystretch{1.25}
\begin{tabular}{|P{1.5cm} | *{8}{P{1.2cm} |}}
\hlineB{2}
& \multicolumn{4}{c|}{Payoffs} & \multicolumn{4}{c|}{ROR} \\
\cline{2-9}
& $\theta =1$ & $\theta =2$ & $E(P)$ & $\sigma(P)$ & $\theta =1$ & $\theta =2$ & $E(r)$ & $\sigma(r)$ \\
\hlineB{2}
Asset 1 & 110 & 95 & & & & & & \\
Asset 2 & 105 & 90 & & & & & & \\
Asset 3 & 120 & 90 & & & & & & \\
\hlineB{2}
\end{tabular}
\end{table}
\vskip1cm
\begin{table}[!h]
\centering\renewcommand\arraystretch{1.25}
\begin{tabular}{P{1.5cm}*{8}{P{1.2cm}}}
& \multicolumn{4}{c}{Payoffs} & \multicolumn{4}{c}{ROR} \\
\cmidrule[0.6pt](lr){2-5}\cmidrule[0.6pt](lr){6-9}
& $\theta =1$ & $\theta =2$ & $E(P)$ & $\sigma(P)$ & $\theta =1$ & $\theta =2$ & $E(r)$ & $\sigma(r)$ \\
\midrule[\heavyrulewidth]
Asset 1 & 110 & 95 & & & & & & \\
Asset 2 & 105 & 90 & & & & & & \\
Asset 3 & 120 & 90 & & & & & & \\
\bottomrule
\end{tabular}
\end{table}

\end{document}