Graphics, Figures & TablesNumbering option for rows in a table

Information and discussion about graphics, figures & tables in LaTeX documents.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Numbering option for rows in a table

Post by phi »

You have to define two counters where one resets the other. Here is a modified version using LaTeX counters instead of TeX integer registers. I've also put the definitions in the preamble where they should be:

Code: Select all

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


        \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
        }
        \newcounter{TL@group}
        \newcounter{TL@task}[TL@group]
        \renewcommand*\theTL@task{\theTL@group.\arabic{TL@task}}
        \newcommand*\Task[1]{%
          \stepcounter{TL@task}%
          \theTL@task&#1%
          \TL@cell\@ne
          \\\hline
        }
        \newcommand*\NewGroup{%
          \stepcounter{TL@group}%
        }
        \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{document}



    \setlength\tabcolsep{1pt}

       
        \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     
         
          %%%%%%%%%%%% 

          \NewGroup
          \NewBlock{blue}{1}{\NumMonths}
          \Task{Literature Review}
         
          %%%%%%   1  %%%%%%%
         
          \NewGroup
          \NewBlock{yellow}{1}{2}
          \Task{Confirmation Exam}
         
          %%%%%%   6   %%%%%%% 4

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

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

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

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

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

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

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

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

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

    \end{document}

Recommended reading 2024:

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

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

pban92
Posts: 54
Joined: Sat Aug 09, 2008 9:34 am

Re: Numbering option for rows in a table

Post by pban92 »

thank you so much bro. awesome work!
Post Reply