[Tex/LaTex] Latex table subdivided columns and rows

booktabstablestexshop

I'm new to Latex and am working TexShop on a MAC OS.

I wanted to create a table with subdivided columns and rows to describe my data, but I seem to have no luck trying to do it with the help of booktabs or array. Basically creating the column where i divide Group A into two more columns, and group B into two more columns is where I'm stuck.

Could somebody please help me out with how to create this kind of table?

enter image description here

EDIT: I want to make the titles bold and colour the table, like we can in Word or Powerpoint. Also, I want to get rid of the horizontal line on the two ends of the top row.

    \documentclass{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage{multirow}
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}             
\usepackage[english,italian]{babel}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry}
\newlength\Colwd
\setlength\Colwd{1.2cm}

\begin{document}

\begin{tabular}{|c|c|c|c|c|c|}
\hline
& \multicolumn{2}{|l|}{Affected} & \multicolumn{2}{|l|}{Unaffected} & Total\\
\hline
& Kids & Adults & Kids & Adults&\\
\hline
Male & 144&15&34&89&282\\
Female & 37&6&66&109&218\\
Total&181&21&99&198&500\\
\hline
\end{tabular}
\end{document}

Best Answer

I would do something like the following:

  • use booktabs (toprule, midrule, cmidrule, bottomrule)
  • do not center-align numbers (mostly they should be right-aligned)
  • remove unnecessary boundaries (lines, horizontally and vertically)
  • add some whitespace (it helps to be more readable)
  • put a headline above every column

table

Code:

\documentclass{article}
\usepackage[english,italian]{babel}
\usepackage{tabularx}
\usepackage{array}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry}

\begin{document}

\begingroup
\renewcommand{\arraystretch}{1.1}
\begin{tabular}{lrrrrr}
\toprule
Gender& \multicolumn{2}{c}{Affected} & \multicolumn{2}{c}{Unaffected} & Total\\
\cmidrule(lr){2-3}\cmidrule(lr){4-5}
& Kids & Adults & Kids & Adults&\\
\midrule
Male & 144&15&34&89&282\\
Female & 37&6&66&109&218\\\addlinespace
Total&181&21&99&198&500\\
\bottomrule
\end{tabular}
\endgroup
\end{document}
Related Question