Graphics, Figures & TablesNumbering option for rows in a table

Information and discussion about graphics, figures & tables in LaTeX documents.
pban92
Posts: 54
Joined: Sat Aug 09, 2008 9:34 am

Numbering option for rows in a table

Post by pban92 »

Hello,

Here is the code for my table

Code: Select all

\documentclass[a4paper,10pt]{article}
\usepackage{rotating}
\usepackage[square, numbers, comma, sort & compress]{natbib} 
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{multirow} 
\usepackage{rotating}

\begin{document}

 \setlength\tabcolsep{1pt}

    \newcommand*\MonthLetters{JFMAMJJASOND}
    \newcommand*\NumMonths{27}
    \newcommand*\YearMonths{12,12,3,}
    \newcommand*\FirstYear{2009}

    \makeatletter
    \newcommand*\YearHeadRow{%
      \expandafter\TL@year@head\number\numexpr\FirstYear\expandafter\relax\expandafter\@nil\YearMonths\@nil
    }
    \def\TL@year@head#1\@nil#2,#3\@nil{%
      &\multicolumn{#2}{c|}{#1}%
      \ifx\\#3\\\else
        \TL@after@fi\TL@year@head\number\numexpr#1+1\relax\@nil#3\@nil
      \fi
    }
    \newcommand*\YearMonthSep[1]{%
      \cline{\numexpr#1+1\relax-\numexpr#1+\NumMonths\relax}%
    }
    \newcommand*\MonthHeadRow{%
      \expandafter\TL@month@head\expandafter\@ne\expandafter\@nil\MonthLetters\@nil
    }
    \def\TL@month@head#1\@nil#2#3\@nil{%
      &#2%
      \ifnum\NumMonths>#1 %
        \TL@after@fi\TL@month@head\number\numexpr#1+1\relax\@nil#3#2\@nil
      \fi
    }
    \newcount\TL@block@first
    \newcount\TL@block@last
    \newcommand*\NewBlock[3]{%
      \xglobal\colorlet{TL@block}{#1}%
      \global\TL@block@first\numexpr#2-1\relax
      \global\TL@block@last\numexpr#3+1\relax
      \ignorespaces
    }
    \newcount\TL@row
    \newcommand*\Row[1]{%
      \global\advance\TL@row\@ne
      \number\TL@row&#1%
      \TL@cell\@ne
      \\\hline
    }
    \def\TL@cell#1{%
      &%
      \ifnum#1>\TL@block@first
        \ifnum#1<\TL@block@last
          \cellcolor{TL@block}%
        \fi
      \fi
      \ifnum\NumMonths>#1 %
        \expandafter\TL@cell\expandafter{\number\numexpr#1+1\expandafter}%
      \fi
    }
    \def\TL@after@fi#1\fi{\fi#1}
    \makeatother
    
    \begin{table}
      \caption{Proposed Reseacrh Timeline}
  \label{minetimeline}
    \begin{tabular}{|c|p{120pt}|*{\NumMonths}{c|}}
      \hline
      \multirow{2}{*}{\#} & \multirow{2}{*}{Tasks} \YearHeadRow \\
      \YearMonthSep{2}
      & \MonthHeadRow \\
      \hline      
      
      %%%%%%%%%%%%  
      
      \NewBlock{blue}{1}{\NumMonths}
      \Row{Literature Review}
      
      %%%%%%   1  %%%%%%%
      
      \NewBlock{yellow}{1}{2}
      \Row{Confirmation Exam}
      
      %%%%%%   6   %%%%%%% 4

      \NewBlock{gray}{3}{5}
      \Row{PIV setup}
      \Row{PIV on $c/t = 7$ with \& without splitter plate}
      \NewBlock{gray}{5}{6}
      \Row{PIV data analysis \& comparison}
      \Row{Explanation of Feedback Loop}
      

      %%%%%%   10    %%%%%%% 5
      
      \NewBlock{green}{7}{9}
      \Row{LDV construction of c/t vs St; $c/t = 3-12$}
      \Row{LDV results analysis}
      \NewBlock{green}{5}{12}
      \Row{PIV experiment on $c/t = 8-9$ and construction}
      \Row{LDV \& PIV data analyze \& comparison}
      \Row{Stepwise variation explanation}
      %\Row{Publication 01}

      %%%%%%     8    %%%%%%% 3

      \NewBlock{orange}{7}{12}
      \Row{Construction of plates with different geometries}
      \NewBlock{orange}{12}{15}
      \Row{PIV on square edges with \& without splitter, aerofoil leading-square trailing edge with \& without splitter}
       \NewBlock{orange}{15}{16}
      \Row{PIV data analyze and comparison}
%      \Row{Publication 02}

      %%%%%%%   7    %%%%%%  3

      \NewBlock{blue}{17}{18}
      \Row{PIV with global oscillation with \& without perturbation}
      \NewBlock{blue}{18}{20}
      \Row{PIV with separate perturbation on aerofoil leading edge \& aerofoil trailing edge}
      \Row{Perturbation data analyze and comparison}
%      \Row{Publication 03}

%%%%%%%%%%     4     %%%%%%%%%%%    2
      
      \NewBlock{green}{15}{21}
      \Row{Pressure probe construction}
      \NewBlock{green}{20}{22}
      \Row{Pressure measurement on $c/t$ = 7 with \& without splitter plate}
      \Row{Pressure data analyze}
      %\Row{Publication 04}  

%%%%%%%%%    1     %%%%%%%%%%%%

      \NewBlock{red}{18}{27}
      \Row{Thesis writing}
     
    \end{tabular}
    
\end{table}

\end{document}
I have a total of 21 tasks and all these tasks can be divided into 5 groups.
The current task number is in the format of 1, 2, 3, 4...20 (in the above code) but I want it as 1.1, 1.2, 1.3...2.1, 2.2 and so on to reflect the task group as well. How to do it?

Please let me know if the problem is not well explained. Any suggestion would be highly appreciated.

Thanks!
Last edited by pban92 on Mon Feb 23, 2009 3:24 am, edited 4 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Numbering option for rows in a table

Post by kaiserkarl13 »

I can't get your example to work: I get the following error message

Code: Select all

! Undefined control sequence.
\YearHeadRow ...er \TL@year@head \number \numexpr
                                                  \FirstYear \expandafter \r...
l.78 ...{\#} & \multirow{2}{*}{Tasks} \YearHeadRow
                                                   \\
?
I'm using the latest versions of all the packages you've included, so that's not the issue.
pban92
Posts: 54
Joined: Sat Aug 09, 2008 9:34 am

Re: Numbering option for rows in a table

Post by pban92 »

I am using texniccenter and I find no problem! :s
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Numbering option for rows in a table

Post by localghost »

I get two errors and they do not depend on the system.

Code: Select all

! Text line contains an invalid character.
l.39       ^^B
              %
! Text line contains an invalid character.
l.55       \number\TL@row^^A
                            %
[1] (./olatex_103182.aux)
Fix them first and then we will see.


Best regards
Thorsten¹
pban92
Posts: 54
Joined: Sat Aug 09, 2008 9:34 am

Re: Numbering option for rows in a table

Post by pban92 »

I am really confused. Separately both texshop (mac) and texniccenter (xp) are compiling in my case without any error. I have no clue why you guys are getting error. :?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Numbering option for rows in a table

Post by localghost »

I get an output (because of nonstop mode), and it looks nice. But I also get these errors. Seems to be a matter of package versions. Put the \listfiles command as very first line to your code, search the log file for the section between *File List* and *********** and post this list here.
pban92
Posts: 54
Joined: Sat Aug 09, 2008 9:34 am

Numbering option for rows in a table

Post by pban92 »

Ok here it is
  • *File List*

    Code: Select all

     article.cls    2005/09/16 v1.4f Standard LaTeX document class
      size10.clo    2005/09/16 v1.4f Standard LaTeX file (size option)
    rotating.sty    2008/06/06 v2.15b rotated objects in LaTeX
    graphicx.sty    1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
      keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
    graphics.sty    2006/02/20 v1.0o Standard LaTeX Graphics (DPC,SPQR)
        trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
    graphics.cfg    2007/01/18 v1.5 graphics configuration of teTeX/TeXLive
      pdftex.def    2008/07/16 v0.04k Graphics/color for pdfTeX
      ifthen.sty    2001/05/26 v1.1c Standard LaTeX ifthen package (DPC)
      natbib.sty    2007/10/30 8.1 (PWD)
      xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
       color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
    colortbl.sty    2001/02/13 v0.1j Color table columns (DPC)
       array.sty    2005/08/23 v2.4b Tabular extension package (FMi)
    multirow.sty    
    supp-pdf.tex
     ***********
Thanks!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Numbering option for rows in a table

Post by localghost »

I managed to sort out the compilation problem. It was a matter of copy and paste of the source code. Somehow there appeared some strange characters in the code after copying it to the editor. This affected only the combination "&#", which appears exactly two times in the code and caused the two errors mentioned earlier. Seemed to be an encoding problem between browser and editor. At the moment I have no solution to the actual problem. But I will report in case I have.
pban92
Posts: 54
Joined: Sat Aug 09, 2008 9:34 am

Re: Numbering option for rows in a table

Post by pban92 »

Thanks localghost, I would keep visiting this thread.
pban92
Posts: 54
Joined: Sat Aug 09, 2008 9:34 am

Re: Numbering option for rows in a table

Post by pban92 »

No further suggestion anybody?
Post Reply