[Tex/LaTex] \toprule and p{} in tabular

tables

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:

enter image description here

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?

Best Answer

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

\multicolumn{4}{c}{ROR}

instead of

\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.

enter image description here

\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.

Related Question