Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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

1 Answer 1

up vote 2 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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