1

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.

enter image description here

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}
\usepackage[includeheadfoot,top=0.25in, bottom=0.25in, left=0.25in, right=0.25in]{geometry} 
\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}
\addtolength\headwidth{0\FHoffset}
\fancyheadoffset{\FHoffset}
\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

migrated from stackoverflow.com Oct 8 '14 at 0:43

This question came from our site for professional and enthusiast programmers.

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Note that I don't understand (iv) at all. – cfr Oct 8 '14 at 1:55
  • 5
    Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on. If no hero takes the challenge we might have to close your question. – cfr Oct 8 '14 at 1:56
  • 6
    Let me expand a bit on @cfr's comments: Speaking from my own experience, it's frequently a fool's errand to try to provide the LaTeX code that mimics a given screen shot. As soon as the code has been provided, the OP points out that he/she doesn't actually want to replicate the screen shot exactly and really wants some further changes, followed by still further change requests when a second code example is produced, etc etc. Trying to answer such vague postings thus quickly becomes a huge time sink -- and I, for one, prefer not to get stuck in such a place... – Mico Oct 8 '14 at 5:24
  • For future reference, please only include code that's relevant to your question. I see lots of things in your code here that have nothing to do with what you're asking (companylogo, FHoffset etc.). Please read meta.tex.stackexchange.com/a/3225/9077 – Sverre Oct 8 '14 at 16:45
4
\documentclass{article}
%---------------------------------------------------------------%
    \usepackage{tabularx,multicol,multirow}
    \usepackage[dvipsnames,table]{xcolor}
%
    \usepackage[labelsep=colon,
                labelfont={bf,sf},
                textfont={sf}]{caption}% added for caption customization
\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}

enter image description here

  • Thanks for the solution. it is helpful. i can expand this to meet my use cases in hand. – user1050134 Oct 9 '14 at 8:59

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.