# Latex table subdivided columns and rows

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?

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}


## 2 Answers

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

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}

• Thank you! This is much better than what I had, and more readable as well. But this table does not show up on my list of tables and I'm guessing it is because of the grouping option? How do I keep the table like this, but also get it to come up as a table in my list of tables? Aug 14, 2017 at 17:26
• @Ar1229 No, it does not show up, because you do not use the table environment around tabular and do not have a caption. Aug 14, 2017 at 17:27
• Okay thats why my \caption{Demogrpahics} didnt work. Any tips on how I can get it to come up? Aug 14, 2017 at 17:30
• @Ar1229 (1) Use the table environment around tabular and caption. or (2) use the caption package and add \captionof{figure}{Demographics}. Aug 14, 2017 at 17:32

After many years (almost five), meanwhile are available new table packages tabularray and nicematrix, your image of table is simple to reproduce. For example, by use of tabularray, you can write:

\documentclass[border=3.141592mm]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\NewTableCommand\scc{\SetCell{bg=cyan!15}} % set cell color

\begin{document}
\begin{tblr}{hlines={1pt, orange}, vlines={1pt, orange},
colspec = {Q[c, wd=4em, font=\large\bfseries]
*{5}{Q[c, wd=4em, si={table-format=3}]}},
row{1}  = {font=\large\bfseries},
rows    = {bg=cyan!30},
rowsep  = {1ex}
}
\SetCell[r=2]{c}
& \SetCell[c=2]{c}  {{{Affected}}}
&       & \SetCell[c=2]{c}  {{{Unaffected}}}
&           & \SetCell[r=2]{c}  {{{Total}}}   \\
&{{{Kids}}} &{{{Adults}}}   &{{{Kids}}} & {{{Adults}}}  &       \\
Male    &\scc 144   &\scc 15        &\scc 34    &\scc  89       & 282   \\
Female  &\scc  37   &\scc  6        &\scc 66    &\scc 109       & 218   \\
Total   & 181       & 21            & 99        & 198           & 500   \\
\end{tblr}
\end{document}