# How to produce this table: Probability datatable with multirow

I want to produce the the following table:

This is my working(only data for Male)

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{multirow}

\begin{document}

\begin{tabular}{|p{1.5cm}|p{2cm}|p{1.5cm}|p{2.7cm}|}\\ \cline{1-4}
\multirow{2}{*}{Exact age}  &\multicolumn{3}{c|}{male}\\ \cline{2-4}
& Death probability & Number of lives  & Life expectancy\\ \cline{1-4}
0                       & 0.007589      & 100,000       & 73.98\\ \cline{1-4}
1                       & 0.000543      & 99,241            & 73.54 \\ \cline{1-4}
2                       & 0.000376      & 99,187            & 72.58 \\ \cline{1-4}
\end{tabular}


And this is what I get:

Note: I'm not interested in thick lines or footnotes.

• The first \\ causes the stray lines at the top. Commented Jun 28 at 12:06
• You're right. That was the first culprit. Thank you for the fast comment. Commented Jun 28 at 12:15
• This is a side note. It is unrelated to the present post. To the nice people who keep upvoting me because I visit this golden website and its brother MSE so many times a day. If I do so, that's because it is part of the process of my learning. And I'm not fishing for any reputation. Anyway thanks a lot for your warm encouragements. Commented Jun 28 at 18:30
• @Rafiq You completely changed your question... the answers obviously don't address this new question. Reverse to your inital question and create a new one.
– JeT
Commented Jun 29 at 11:43

If you don't mind using the tabularray package, things are really easy

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{
colspec = {Q[c] Q[c] Q[c] l},
cell{1}{2} = {c=3}{c},
hline{1,3} = {-}{},
hline{2} = {2-4}{},
}
{Exact\\age} & {male} & & \\
& {Death\\probability} & {Number\\of lives} & {Life\\expectancy} \\
0 & \num{0.007589} & \num{100000} & \num{73.98} \\
1 & \num{0.000543} & \num{99241} & \num{73.54} \\
2 & \num{0.000376} & \num{99187} & \num{72.58} \\
\hline
\end{tblr}

\end{document}


and with the booktabs options with tabularray

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\begin{tblr}{
colspec = {Q[c] Q[c] Q[c] l},
cell{1}{2} = {c=3}{c},
hline{2} = {2-4}{},
}
\toprule
{Exact\\age} & {male} & & \\
& {Death\\probability} & {Number\\of lives} & {Life\\expectancy} \\
\midrule
0 & \num{0.007589} & \num{100000} & \num{73.98} \\
1 & \num{0.000543} & \num{99241} & \num{73.54} \\
2 & \num{0.000376} & \num{99187} & \num{72.58} \\
\bottomrule
\end{tblr}

\end{document}

• Thanks @Jet. Now I'm focusing to learn tables as best as I could. Commented Jun 28 at 17:18
• then spend time on tabularray :)
– JeT
Commented Jun 28 at 17:33
• I'll do. Be sure of that. Commented Jun 28 at 18:22
• Following the kind comment by Zarko, I accept your answer. The other answers are also beneficial to me. Commented Jul 4 at 11:10

As commented, the first \\ causes the extra vertical lines. Also, \cline{1-4} is equivalent to \hline, which better describes how you're using it.

But I would redesign the table a bit. The first thing is to use booktabs and take its advice: vertical lines kill puppies, and horizontal lines are usually unnecessary (more seriously, lines should not be necessary to help interpret the data in a table, and can actually hinder interpretation). We can also use siunitx to have it format the numbers and line things up nicely. (And to keep the line breaks, we'll use \specialcell from https://tex.stackexchange.com/a/19678/107497). I end up with:

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{siunitx}

\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}

\begin{document}

\begin{tabular}{
S[table-format=1]
S[table-format=1.6]
S[table-format=6]
S[table-format=2.2]}\toprule
{\multirow{2}{*}{\specialcell{Exact\\age}}} & \multicolumn{3}{c}{male}\\ \cmidrule(l){2-4}
& {\specialcell{Death\\probability}}
& {\specialcell{Number\\of lives}}
& {\specialcell{Life\\expectancy}} \\ \midrule
0   & 0.007589      & 100000     & 73.98 \\
1   & 0.000543      & 99241      & 73.54 \\
2   & 0.000376      & 99187      & 72.58 \\\bottomrule
\end{tabular}

\end{document}


which renders as

When you go to include females, you'll want to change the \cmidrule(l) to (lr). And as a bonus, this table is a little more compact (although that is mostly due to new linebreaks in the first and last columns).

• Thanks for your answer. I'll take your advice into account. I struggled a lot with this table. Commented Jun 28 at 16:20

One more solution using tabularray package. In it is employed siunitx package for defining column types and tblr-extras for defining caption style using caption package:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,
caption,
siunitx}
\usepackage{caption}
\captionsetup[table]{skip=1ex,
font = {small, sf},
labelfont = bf,
justification=centerlast
}

\begin{document}
\begin{table}[ht]
\centering
\begin{talltblr}[
caption = {This table is about something},
label = {tblr:something},
LE: Life expectancy}
]{colspec = {Q[c, si={table-format=1}]
*{2}{Q[c, si={table-format=1.6}]
Q[c, si={table-format=7}]
Q[c, si={table-format=2.2}]}
},
cell{1}{1} = {r=2}{},
cell{1}{2,5} = {c=3}{},
row{1,2}  = {guard}
}
\toprule
{Exact\\age}
&   Male    &           &           &   Female  &           &       \\
\cmidrule[lr]{2-4}
\cmidrule[lr]{5-7}
&   DL      & NL        &   LE      &   DL      & NL        &   LE  \\
\midrule
0 & 0.007589   & 100000    & 73.98     & 0.007589  & 100000    & 73.98 \\
1 & 0.000543   &  99241    & 73.54     & 0.000543  &  99241    & 73.54 \\
2 & 0.000376   &  99187    & 72.58     & 0.000376  &  99187    & 72.58 \\
\bottomrule
\end{talltblr}
\end{table}
\end{document}


• Thanks for promoting my small package Commented Jun 30 at 23:32
• @Mane32, your are welcome. Your package is excellent. Now I use it at talltblr and longtblr regularly. Thank you for for it! Commented Jul 1 at 5:20
• @Mane32 i'll follow zarko on this. Thank you.
– JeT
Commented Jul 4 at 16:33

A suggestion with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix,booktabs,siunitx}

\begin{document}

\begin{NiceTabular}{cccc}
\toprule
\Block[t]{2-1}{Exact\\ age} & \Block{1-3}{male} \\
\cmidrule(l){2-4}
& \Block{}{Death\\probability} & \Block{}{Number\\ of lives} & \Block{}{Life\\ expectancy} \\
\midrule
0 & \num{0.007589} & \num{100000} & \num{73.98} \\
1 & \num{0.000543} & \num{99241} & \num{73.54} \\
2 & \num{0.000376} & \num{99187} & \num{72.58} \\
\bottomrule
\end{NiceTabular}

\end{document}


• Thanks for sharing with me a little knowledge. I hope I could soon be able to learn fast, and absorb a great quantity. Commented Jun 30 at 13:35

If you really like caged tables:

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{multirow}

\begin{document}

\begin{tabular}{|p{1.5cm}|p{2cm}|p{1.5cm}|p{2.7cm}|}\\ \cline{1-4}
\multirow{2}{*}{Exact age}  &\multicolumn{3}{c|}{male}\\ \cline{2-4}
& Death probability & Number of lives  & Life expectancy\\ \cline{1-4}
0                       & 0.007589      & 100,000       & 73.98\\ \cline{1-4}
1                       & 0.000543      & 99,241            & 73.54 \\ \cline{1-4}
2                       & 0.000376      & 99,187            & 72.58 \\ \cline{1-4}
\end{tabular}


Using a legend, the size of the columns can be kept tight.

An open look is, in my opinion, much better.

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{booktabs}

\sisetup{
group-digits=integer,
group-separator={,},
}

\begin{document}

\begin{table}[htp]
\centering

\begin{tabular}{
@{}
c
S[table-format=1.6]
S[table-format=6.0]
S[table-format=2.2]
S[table-format=1.6]
S[table-format=6.0]
S[table-format=2.2]
@{}
}
\toprule
\smash{\begin{tabular}[t]{@{}c@{}}Exact \\ age\end{tabular}}
& \multicolumn{3}{c}{Male}
& \multicolumn{3}{c@{}}{Female} \\
\cmidrule(lr){2-4} \cmidrule(l){5-7}
& {DP} & {NL} & {LE} & {DP} & {NL} & {LE} \\
\midrule
0 & 0.007589 & 100000 & 73.98 & 0.007589 & 100000 & 73.98 \\
1 & 0.000543 &  99241 & 73.54 & 0.000543 &  99241 & 73.54 \\
2 & 0.000376 &  99187 & 72.58 & 0.000376 &  99187 & 72.58 \\
\midrule[\heavyrulewidth]
\multicolumn{7}{@{}l@{}}{%
\footnotesize
LE: Life expectancy%
}
\end{tabular}

\end{table}

\end{document}


• Thank you so much for your invaluable help and for all your contributions. Commented Jun 29 at 13:19

From all the answers I got, now I Know how a professional table must be made. That said, I kept asking how did my book make that original one. And I figured out.

\begin{tabular}{|l|l|l|l|l|l|l|}\cline{1-7}
&\multicolumn{3}{|c|}{male} & \multicolumn{3}{c|}{Female}\\ \cline{2-7}
Exact &Death      &Number & Life            &Death      &Number & Life\\
age   &probability & of lives  & expectancy & probability & of lives & expectancy   \\ \cline{1-7}
0      & 0.007589 & 100,000 & 73.98      & 0.006234  & 100,000 & 79.35      \\ \cline{1-7}
1     & 0.000543  & 99,241   & 73.54         & 0.000447  & 99,377   & 78.84         \\ \cline{1-7}
2    &  0.000376  & 99,187   & 72.58         & 0.000376  & 99,187   & 72.58          \\ \cline{1-7}
\end{tabular}


to get rid of some horizontal lines, some c lines must be deleted

\begin{tabular}{|l|l|l|l|l|l|l|}\cline{1-7}
&\multicolumn{3}{|c|}{male} & \multicolumn{3}{c|}{Female}\\ \cline{2-7}
Exact &Death      &Number & Life            &Death      &Number & Life\\
age   &probability & of lives  & expectancy & probability & of lives & expectancy   \\ \cline{1-7}
0      & 0.007589 & 100,000 & 73.98      & 0.006234  & 100,000 & 79.35      \\
1     & 0.000543  & 99,241   & 73.54         & 0.000447  & 99,377   & 78.84         \\
2    &  0.000376  & 99,187   & 72.58         & 0.000376  & 99,187   & 72.58          \\ \cline{1-7}
\end{tabular}


• Hm, table design as proposed in other answers are more appealing and with much clearer code. You should consider to accept one of them. Commented Jul 4 at 8:45
• How could I accept one of them. They're all so good to me! Commented Jul 4 at 9:56
• Simple, select one, which you the most liked. Until you will not accept one, your question will treat as unsolved ... Commented Jul 4 at 12:19
• I just did. See the first answer. Thank you. Commented Jul 4 at 12:59