4

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.

  • Welcome to tex.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. – Edd Apr 4 '11 at 13:31
2

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.