# How to get table row sub numbering?

I am trying to get serial numbers in table, but some of the rows require sub numbering as shown below:

S. No. X    Y   Z
1   1   12  1
2   4   34  3
3   5   54  2
4.a 6   34  5
4.b 8   32  7
5   1   44  7
6   4   11  4
7   6   45  2
8.a 3   23  5
8.b 4   43  4
8.c 3   54  2
8.d 1   65  1
9   1   76  3
10  5   87  4


How to get such row sub numbering in LaTeX?

MWE

\documentclass{article}
\begin{document}
\begin{table}[]
\centering
\caption{Row sub numbering}
\label{my-label}
\begin{tabular}{llll}
S. No. & X & Y  & Z \\
1      & 1 & 12 & 1 \\
2      & 4 & 34 & 3 \\
3      & 5 & 54 & 2 \\
4.a   & 6 & 34 & 5 \\
4.b   & 8 & 32 & 7 \\
5      & 1 & 44 & 7 \\
6      & 4 & 11 & 4 \\
7      & 6 & 45 & 2 \\
8.a   & 3 & 23 & 5 \\
8.b   & 4 & 43 & 4 \\
8.c   & 3 & 54 & 2 \\
8.d   & 1 & 65 & 1 \\
9      & 1 & 76 & 3 \\
10     & 5 & 87 & 4 \\
\end{tabular}
\end{table}
\end{document}

• Please clarify where the serial number information and where the subnumber information is located.
– Mico
Apr 9 '16 at 19:42

Using the suspension and resume feature of xassoccnt it is possible to setup a N columntype that acts either regular as counting rows or enters a subrow feature.

Use \enablesubrow before the requested subrow and \disablesubrow before switching back to the old numbering style.

Since table cells are (La)TeX groups, setting a conditional must be done globally to let the setting survive from one group to the next one, i.e. use \global\subrowtrue and \global\subrowfalse.

\documentclass{article}
\usepackage{array}

\usepackage{xassoccnt}
\newcounter{rowcntr}[table]
\newcounter{realrowcntr}[table]
\newcounter{subrowcntr}
\newif\ifsubrow

\newcommand{\enablesubrow}{%
\global\subrowtrue%
}

\newcommand{\disablesubrow}{%
\global\subrowfalse%
\ResumeSuspendedCounters{rowcntr}%
\setcounter{subrowcntr}{0}% Reset subrows
}

\renewcommand{\thesubrowcntr}{%
\ifsubrow
\stepcounter{subrowcntr}%
\therowcntr.\alph{subrowcntr}%
\else
\therowcntr%
\fi
}

\newcommand{\checksubrowstuff}{%
\stepcounter{realrowcntr}%
\ifnum\value{realrowcntr}>1
\stepcounter{rowcntr}%
\ifsubrow
\SuspendCounters{rowcntr}% Do not increase any longer
\fi
\thesubrowcntr%
\fi
}

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}%
\newcolumntype{N}[1]{>{\checksubrowstuff\arraybackslash}R{#1}}
\begin{document}
\begin{table}
\centering
\caption{Row sub numbering}
\label{my-label}
\begin{tabular}{N{1.5cm}lll}
S. No. & X & Y  & Z \\
& 1 & 12 & 1 \\
& 4 & 34 & 3 \\
& 5 & 54 & 2 \enablesubrow \\
& 6 & 34 & 5 \\
& 8 & 32 & 7 \disablesubrow \\
& 1 & 44 & 7 \\
& 4 & 11 & 4 \\
& 6 & 45 & 2 \enablesubrow\\
& 3 & 23 & 5 \\
& 4 & 43 & 4 \\
& 3 & 54 & 2 \\
& 1 & 65 & 1 \disablesubrow\\
& 1 & 76 & 3 \\
& 5 & 87 & 4 \\
\end{tabular}
\end{table}
\end{document}