LaTeX.org

LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Numbering 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 » Sat Mar 07, 2009 12:15 pm

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:

\documentclass[a4paper,10pt] \usepackage \usepackage[square, numbers, comma, sort & compress] \usepackage \usepackage \usepackage \usepackage \newcommand*\MonthLetters \newcommand*\NumMonths \newcommand*\YearMonths \newcommand*\FirstYear \makeatletter \newcommand*\YearHeadRow \def\TL@year@head#1\@nil#2,#3\@nil% \ifx\\#3\\\else \TL@after@fi\TL@year@head\number\numexpr#1+1\relax\@nil#3\@nil \fi > \newcommand*\YearMonthSep[1]% > \newcommand*\MonthHeadRow \def\TL@month@head#1\@nil#2#3\@nil#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]% \global\TL@block@first\numexpr#2-1\relax \global\TL@block@last\numexpr#3+1\relax \ignorespaces > \newcounter \newcounter[TL@group] \renewcommand*\theTL@task<\theTL@group.\arabic> \newcommand*\Task[1]<% \stepcounter% \theTL@task% \TL@cell\@ne \\\hline > \newcommand*\NewGroup<% \stepcounter% > \def\TL@cell#1\TL@block@first \ifnum#1<\TL@block@last \cellcolor% \fi \fi \ifnum\NumMonths>#1 % \expandafter\TL@cell\expandafter% \fi > \def\TL@after@fi#1\fi \makeatother \begin \setlength\tabcolsep \begin \caption \label \begin<|c|p<120pt>|*<\NumMonths>> \hline \multirow & \multirow \YearHeadRow \\ \YearMonthSep & \MonthHeadRow \\ \hline %%%%%%%%%%%% \NewGroup \NewBlock <\NumMonths>\Task %%%%%% 1 %%%%%%% \NewGroup \NewBlock \Task %%%%%% 6 %%%%%%% 4 \NewGroup \NewBlock \Task \Task \NewBlock \Task \Task %%%%%% 10 %%%%%%% 5 \NewGroup \NewBlock \Task \Task \NewBlock \Task \Task \Task %\Row %%%%%% 8 %%%%%%% 3 \NewGroup \NewBlock \Task \NewBlock \Task \NewBlock \Task % \Row %%%%%%% 7 %%%%%% 3 \NewGroup \NewBlock \Task \NewBlock \Task \Task % \Row %%%%%%%%%% 4 %%%%%%%%%%% 2 \NewGroup \NewBlock \Task \NewBlock \Task \Task %\Row %%%%%%%%% 1 %%%%%%%%%%%% \NewGroup \NewBlock \Task \end \end \end

Recommended reading 2024: