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.

In addition to tables and figures, I have a bunch of code pieces. Just like follows:

    \begin{figure}
    \lstinputlisting[
    language=C++, breaklines=true,
    keywordstyle=\color{blue},
    commentstyle=\color{mygreen},
    stringstyle=\color{red},
    frame=single,
    backgroundcolor=\color{gray},
    basicstyle=\footnotesize\ttfamily,
    caption={Data acquisition code},
    label={code:data}]
    {codes/data.cpp}
\end{figure}

Those codes do not appear in table of figures or table of contents which is exactly what I want.

Now I want to create a new table of codes \listofcodes similar to \listoffigures. It should create a third table. How do I do that?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

If you are using the listings package, then you have \lstlistoflistings to generate a list of listings. I see that you are enclosing your lstinputlistings in a figure environment; if the idea is to turn them into floats then you could use the float option; a little example:

\documentclass{book}
\usepackage{listings}

\begin{document}
\lstlistoflistings

%A non-floating listing:
\begin{lstlisting}[caption={Useless code one},label=uselessone]
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{lstlisting}

%A floating listing:
\begin{lstlisting}[float,caption={Useless code two},label=uselesstwo]
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{lstlisting}

\end{document}

EDIT: corrected the example according to Andrey Vihrov's comment.

share|improve this answer
    
You are a lifesaver. Thanks! –  Dan Paradox Jun 1 '11 at 4:40
1  
This isn't the correct usage. listings has the float parameter. –  Andrey Vihrov Jun 1 '11 at 6:43
    
@Andrey Vihrov: thanks. I've edited my answer accordingly. –  Gonzalo Medina Jun 1 '11 at 11:32

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.