0

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}
0

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}
  • 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? – Ar1229 Aug 14 '17 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. – TeXnician Aug 14 '17 at 17:27
  • Okay thats why my \caption{Demogrpahics} didnt work. Any tips on how I can get it to come up? – Ar1229 Aug 14 '17 at 17:30
  • @Ar1229 (1) Use the table environment around tabular and caption. or (2) use the caption package and add \captionof{figure}{Demographics}. – TeXnician Aug 14 '17 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.