2

I would like to recreate the following table in LaTeX.

enter image description here

I was able to make most of the table using the code provided below. I found code for making a table with several dimensions here but it wasn't quite what I wanted.

\begin{center} \begin{tabular}{ccc} \toprule & \multicolumn{2}{c}{Death 
Penalty} 
\\ \cmidrule{2-3} Defendant's Race & Yes & No\\ \midrule 
White & 19& 132\\ 
Black & 11& 52\\ 
White & 0&  9\\ 
Black & 6&  97\\ 
\bottomrule \end{tabular} \end{center}

enter image description here

I tried the following code but it didn't work. Any help would be greatly appreciated!

\begin{center} \begin{tabular}{cccc} \toprule & \multicolumn{2}{c}{Death 
Penalty} 
\\ \cmidrule{3-4} Victim's Race &Defendant's Race & Yes & No\\ \midrule 
White & White & 19& 132\\ 
&Black & 11&    52\\ 
Black&White & 0&    9\\ 
Black & 6&  97\\ 
\bottomrule \end{tabular} \end{center}
7
  • Add a second & after toprule as well as in the beginning of the last row.
    – leandriis
    Oct 4, 2019 at 5:32
  • Thanks, it worked. Could you explain what toprule && is doing?
    – Remy
    Oct 4, 2019 at 5:43
  • 1
    \toprule adds the horizontal rule on top of the table, while && crate two empty cells. This is needed since the frst text in the firs row is in the third+fourth column.
    – leandriis
    Oct 4, 2019 at 5:47
  • Does \multicolumn{2}{c} mean "Death Penalty" will take up two columns and \cmidrule{3-4} mean there will be a horizontal line above just the third and fourth column? I have been using sample code and am just using my intuition here...
    – Remy
    Oct 4, 2019 at 5:54
  • 1
    Your above assumption about multicolumn and cmidrule is correct. Regarding the packages: make a copy of your document, remove all contents but keep the table in question. Then comment out some packages and compile. If the document is still compilable and the output stays the same, these packages are not relevant. Repeat until you have the smallest possible document.
    – leandriis
    Oct 4, 2019 at 6:24

2 Answers 2

1

Fran was a little bit faster with their answer. However, here is a slightly different layout using multirow, and siunitx:

enter image description here

\documentclass{article}

\usepackage{booktabs}

\usepackage{siunitx}
\usepackage{multirow}
\usepackage{makecell}

\begin{document}
\begin{tabular}{cc*{2}{S[table-format=2]}} 
\toprule 
& & \multicolumn{2}{c}{Death Penalty} \\ 
\cmidrule{3-4} 
\multirow{-2.5}{*}{\makecell{Victim's\\ Race}} & \multirow{-2.5}{*}{\makecell{Defendant's\\ Race}} & {Yes} & {No}\\ 
\midrule 
White & White & 19& 132\\ 
&Black & 11&    52\\ \addlinespace
Black&White & 0&    9\\ 
& Black & 6&  97\\ 
\bottomrule 
\end{tabular} 
\end{document}
2
  • 1
    +1, I also thought about use sinutix, but in this case, due to the multicolumn cell, for my taste left too much space at the right, so I opted for a simply r column.
    – Fran
    Oct 4, 2019 at 8:02
  • @Fran: Thanks for pointing this out. I didn't even notice the small extra space at the right.
    – leandriis
    Oct 4, 2019 at 8:33
4

Choose the one you prefer:

mwe

\documentclass[twocolumn]{article}
\usepackage{booktabs,lipsum,parskip}    
\usepackage{multirow}   
\begin{document}

\lipsum[1][1-4]

\begin{table}[h]
\caption{Number of deaths per involved races.}
\begin{tabular}{@{}lccc@{}} 
\toprule 
&  & \multicolumn{2}{c}{Death Penalty}\\\cmidrule{3-4} 
Victim's Race & Defendant's Race & Yes & No\\ \midrule 
White  & White & 19& 132\\ 
& Black & 11& 52\\ 
Black & White & 0&  9\\ 
& Black & 6&  97\\\bottomrule 
\end{tabular}
\end{table}

\lipsum[2][7-10]


\newpage

\lipsum[1][1-4]

\begin{table}[h]
\caption{Number of deaths per involved races.}
\centering
\begin{tabular}{llrr} 
\toprule 
\multirow{2}{*}{\parbox{4em}{Victim's Race}} & \multirow{2}{*}{\parbox{6em}{Defendant's Race}}  & \multicolumn{2}{c}{Death Penalty}\\\cmidrule{3-4} 
 &  &  Yes & No\\ \midrule 
White  & White & 19& 132\\ 
& Black & 11& 52\\ 
Black & White & 0&  9\\ 
& Black & 6&  97\\\bottomrule 
\end{tabular}
\end{table}

\lipsum[2][7-10]

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .