[Tex/LaTex] Custom numbering of listings

counterslistingsnumbering

I have a number of listings in my document, numbered 1, 2, 3 and so on.
I need a table with three listings (say, three different variants of the same algorithm), that will be numbered as 2a, 2b, 2c. The very next listing would be numbered as 3.

Best Answer

you can also save the current counter value to make it independent from the current counter setting.

\documentclass{article}
\usepackage{listings}
\begin{document}

\begin{lstlisting}[caption=foo]
 foo
\end{lstlisting}

\setcounter{lstlisting}{0}
\renewcommand\thelstlisting{2.\alph{lstlisting}}
\begin{lstlisting}[caption=foo]
 foo
\end{lstlisting}
\begin{lstlisting}[caption=foo]
 foo
\end{lstlisting}
\begin{lstlisting}[caption=foo]
 foo
\end{lstlisting}

\renewcommand\thelstlisting{\arabic{lstlisting}}
\setcounter{lstlisting}{2}
\begin{lstlisting}[caption=foo]
 foo
\end{lstlisting}

\end{document}