# Adding table with restricted horizontal line

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

I tried:

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

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – strpeter May 6 '14 at 8:00

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}


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}


• @HarishKumar If I need another horizontal line, say under the text "Average". What changes do I do? – Madhav Pai May 8 '14 at 3:13
• @MadhavPai In the first example, use \cmidrule{2-3}\cmidrule(l{1ex}r{1ex}){4-4} (another \cmidrule). In the second exabove, use \smashedcell{Average \\\hline duration, $N_a$} (extra \hline). – user11232 May 8 '14 at 5:12

or with help of siunitx and multirow

\documentclass{article}
\usepackage{booktabs,multirow,siunitx}
\begin{document}
\begin{tabular}{*{4}{S}}
\toprule
&   \multicolumn{2}{c}{Probability of}  &
\multirow{2}{2cm}{\centering
Average\newline  duration, $N_a$}  \\
\cmidrule{2-3}
{Capital, $a$}  &   {Ruin}      &   {Success}           &       \\
\midrule
9               &   0.1         &   0.9                 &   9   \\
90              &   0.10        &   0.90                & 900   \\
900             &   0.053       &   0.947               & 450   \\
\bottomrule
\end{tabular}
\end{document}


where for last column instead of showed multirow construction for head of the last column you can use very interesting egreg refinement given in the first answer.