Adding Table with Restricted Horizontal Line – Multicolumn Tables

multicolumntables

I am new to LaTeX and having a hard time trying to figure out a way to draw a table like the one in the image below.

  • To be precise, how do I get the horizontal line only above the texts "Ruin" and "Success".
  • Another issue is how to align the text "Probability of" exactly between "Ruin" and "Success".

MWE Tabular

I tried:

\begin{tabular}{c c  c p{2cm}}
\hline
&&Probability of \\
Capital,$a$ & Ruin & Success & Average duration,$N_a$  \\ 
\hline
\end{tabular}

Best Answer

You can use \multicolumn and \cmidrule from booktabs package.

\documentclass{article}
\usepackage{booktabs}
\begin{document}
  \begin{tabular}{c c  c c}
\toprule
&\multicolumn{2}{c}{Probability of} & Average \\\cmidrule{2-3}
Capital, $a$ & Ruin & Success &  duration, $N_a$  \\
\midrule
9 & 0.1 & 0.9 & 0.9 \\
9 & 0.1 & 0.9 & 0.9 \\ \bottomrule
\end{tabular}
\end{document}

enter image description here

For more details on \cmidrule refer to the documentation of booktabs package.

A possible refinement for the last header:

\documentclass{article}
\usepackage{booktabs}

\newcommand{\smashedcell}[1]{%
  \strut\smash{\begin{tabular}[b]{@{}c@{}}#1\end{tabular}}%
}

\begin{document}
  \begin{tabular}{c c  c c}
\toprule
&\multicolumn{2}{c}{Probability of} & \\
\cmidrule{2-3}
Capital, $a$ & Ruin & Success & \smashedcell{Average \\ duration, $N_a$}  \\
\midrule
9 & 0.1 & 0.9 & 0.9 \\
9 & 0.1 & 0.9 & 0.9 \\ 
\bottomrule
\end{tabular}
\end{document}

enter image description here

Related Question