# [Tex/LaTex] Complex nested table in LATEX

longtabletables

In my document I want to include nested tables as in the picture below.

i- The table need to occupy the page width

ii- The left most column "GRP1" & "GRP2" to be left aligned on the page

iii- The column for aggregate percentage on right to be right aligned but the value in that to be centered.

iv – In the center column – the description to be left aligned. The nested part details table in the same column to be left aligned. the number of parts are variable. It could vary from 0 to 50. However in the same line maximum of 15 only can come. Remaining then will move to next line.

Need help in how to do the same in LATEX.

** EDIT**

I accept my mistake in forgetting the guideline and raising question without mentioning what I tried.
Adding the code that I'm trying. Being beginner the code does not yet follow the best practice for tex coding.

    \documentclass[a4paper,12pt]{report}
\usepackage{graphicx}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{xcolor,colortbl}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{tabu}
\def\companylogo{\rule{2cm}{2cm}}
\definecolor{pwcolor}{RGB}{219, 48, 122}
\setlength\headheight{40pt} %% just to make warning go away. Adjust the value after looking into the warning.
\newlength\FHoffset
\setlength\FHoffset{0cm}
\title{My first report}
\date{2014-10-02}
\begin{document}
Hello World!\\

\begin{longtable}{l|c|r}
\cellcolor{blue!25}{Group-A}
&{
\begin{tabular}{llllllllll}
\multirow{3}{*} {} &
\multicolumn{9}{l}{Description1} & \\
{} &Q1 & Q2 & Q3 & Q4 & Q5 & Q6 & Q7 & Q8 & Q9  \\
{} &1  & 2  & 3  & 4  & 5  & 6  & 7  & 8  & 9
\end{tabular}
}
&\cellcolor{blue!25}{25}
\\
\hline
\cellcolor{red!25}{Group-B}
&{
\begin{tabular}{llllllllll}
\multirow{3}{*} {} &
\multicolumn{9}{l}{Description2} & \\
{} &Q1 & Q2 & Q3 & Q4 & Q5 & Q6 & Q7 & Q8 & Q9  \\
{} &1  & 2  & 3  & 4  & 5  & 6  & 7  & 8  & 9
\end{tabular}
}
&\cellcolor{red!25}{75}
\end{longtable}

\lipsum
\end{document}


the output table produced by this code is not getting aligned as per the page width.

More than code I would like some reference to approach this problem.

For point 4 – above where I mentioned that center column will have sub-table with dynamic column count. Currently I'm thinking to generate .tex file programmatically and then pass the output tex file from that utility for further processing.

thanks

\documentclass{article}
%---------------------------------------------------------------%
\usepackage{tabularx,multicol,multirow}
\usepackage[dvipsnames,table]{xcolor}
%
\usepackage[labelsep=colon,
labelfont={bf,sf},
\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}
%
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
\begin{table}
\sffamily
\caption{My beautiful table}
\begin{tabularx}{\linewidth}{|C|*{6}{X|}}
\hline
\cellcolor{green}{}
&   \multicolumn{5}{c|}{\cellcolor{gray!30}{description 1}}
&  \hfill \cellcolor{gray!30}{70\%}                         \\
\cline{2-7}
\cellcolor{green}{}
&  P1         &  P2         &  P3         &  P4         &  P5         & \\
\cline{2-6}
\multirow{-3}{*}{\cellcolor{green}{GRP1}}
& \hfill 60\% & \hfill 60\% & \hfill 60\% & \hfill 80\% & \hfill 90\% & \\
\hline
\cellcolor{cyan}{}
&   \multicolumn{5}{c|}{\cellcolor{gray!30}{description 2}}
&  \hfill \cellcolor{gray!30}{70\%}                                 \\
\cline{2-7}
\cellcolor{cyan}{}
& P11         & P12         & P13        & P14         & P15          & \\
\cline{2-6}
\multirow{-3}{*}{\cellcolor{cyan}{GRP2}}
& \hfill 60\% & \hfill 60\% & \hfill 60\% & \hfill 80\% & \hfill 90\% & \\
\hline
\end{tabularx}
\end{table}
\end{document}