# Getting started with TeX - my first table (a nested table)

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
• 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.

-
I'm confused with why you're using LaTeX to make this table. Complex table layouts are one of LaTeX's weakest points. Do you want to do this in LaTeX just so you can generate the data using Sweave? –  rdhs Mar 25 '12 at 15:47
Hi Homunculus, welcome to tex exchange! It's usually better to show what you have first- The Indian TUG page has some excellent examples that might get you started- perhaps you could try that, and then edit your question :) –  cmhughes Mar 25 '12 at 15:55
@rdhs: What are the alternatives for creating a table? (like I said, I'm new to this - so this may indeed, not be the best approach, although my preliminary research seems to indicate otherwise). I need to dynamically generate this table for a publication. I saw Sweave some time back, but it was not intuitive. I am working with Python mostly (as far as scripting languages go), and I wanted to dynamically generate the LaTeX string for the document (populated with the data). It will be a lot faster for me to do this than to learn Sweave. –  Homunculus Reticulli Mar 25 '12 at 15:56
Check back on your related question for part of a solution. If you have the data in Python, you should be able to replace my dummy values with the real ones. –  Mike Renfro Mar 25 '12 at 16:21
Thanks Mike, I'm on it ... –  Homunculus Reticulli Mar 25 '12 at 16:28

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}


-

It seems that Excel2LaTeX will be able to reproduce most of the layout your asking for, and even more. (Are you fine with double lines instead of thick lines?) It runs on Windows and MacOS (using a beta version, see bug report), and you will need it only for translating the Excel sheet into LaTeX. (That is, the LaTeX document doesn't have to be compiled in Windows.)

Simply insert what this tool produces into Scribus, be sure to leave out the figure environment, though. The layout you ask for requires extra packages such as multirow, not sure if Scribus allows for this.

See also the Comprehensive list of tools that simplify the generation of LaTeX tables (work in progress).

On that note: I wouldn't actually call your table a "nested table". Perhaps "merged columns" would be more appropriate.

-