[Tex/LaTex] Getting started with TeX – the first table (a nested table)

nestingtables

I am brand new to LaTeX, and I am trying to create a LaTeX string to create a report with a known format. I will be inserting my LaTeX string into an A4 page in a scribus document.

Accoring to the Scribus documentation on using LaTex:

Just type your LaTeX code, but remember: The preamble and the end is
added automatically during processing. So only add the parts between

\begin{document}

and

\end{document}

Since I am new to this, I will be very grateful if one of the experts in here can help me get started with creating the LaTeX string to generate a report of the nested table structure shown below.

What I am struggling with in particular are:

  • the nesting of the columns (e.g. Main table -> Gender -> weight/height -> stats
  • The shading of the column header cells
  • Drawing lines with different shades of grey to separate between birthday, weight and height.

I will be very grateful for a LaTeX snippet that shows me how to generate such a report.

enter image description here

Best Answer

should also work with longtable

\documentclass[landscape,a4paper]{article}
\usepackage[margin=1cm]{geometry}
\usepackage[table]{xcolor}
\usepackage{array,ragged2e}
\newcolumntype{C}{>{\Centering}p{1.5em}}
\def\Vrule{\vrule width 1pt}
\begin{document}

\footnotesize
\def\arraystretch{1.2}
\begin{tabular}{r
                |*4{C!{\color{black!50}\vrule}} C |
                 *4{C!{\color{black!50}\vrule}} C
                 !{\Vrule} c !{\Vrule}
                 *4{C!{\color{black!50}\vrule}} C |
                 *4{C!{\color{black!50}\vrule}} C |}
\multicolumn{1}{c}{}
 & \multicolumn{10}{c}{\bfseries Male} & 
   \multicolumn{1}{c}{\rule{1.5cm}{0pt}} & 
   \multicolumn{10}{c}{\bfseries Male}\\\cline{2-22}

 & \multicolumn{5}{|c}{weight} & \multicolumn{5}{|c}{height} & 
   \multicolumn{1}{!{\Vrule}c}{} &
   \multicolumn{5}{|c}{weight} & \multicolumn{5}{|c|}{height} \\\cline{2-11}\cline{13-22}
\rowcolor{black!20}
\textbf{Birthday} &
\textbf{min} & \textbf{q1} & \textbf{med} & \textbf{q3} & \textbf{max} & 
\textbf{min} & \textbf{q1} & \textbf{med} & \textbf{q3} & \textbf{max} &
  \cellcolor{white}\raisebox{1.5ex}{\textbf{Power}} &
\textbf{min} & \textbf{q1} & \textbf{med} & \textbf{q3} & \textbf{max} &
\textbf{min} & \textbf{q1} & \textbf{med} & \textbf{q3} & \textbf{max} \\\cline{2-22}

\textbf{Jan 2012} & & & & & & & & & & & 100 & & & & & & & & & & \\\cline{2-22}
                  & & & & & & & & & & & 110 & & & & & & & & & & \\\cline{2-22}
\end{tabular}
\end{document}

enter image description here