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.

Is there a way to exclude a specific listing from being printed in the LoL? I put one in a figure environment for the sake of not being printed on two seperate pages. But now I have the figure as well as the listing in the toc

\documentclass{article}

\usepackage{tikz}
\usepackage{listings}


\begin{document}
\lstlistoflistings
\listoffigures
\begin{figure}
\begin{lstlisting}[caption=Listing]

\end{lstlisting}
\caption{Figure}
\end{figure}

\end{document}

Update:

I used this to have a special listing caption for all real listings.

\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
  \parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{\bf\sffamily\smaller#1#2#3}}\vskip-1pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
share|improve this question
    
Don't use \caption? And why do you use figure to avoid a page break. Maybe a minipage is better for your situation. –  knut Jan 3 '13 at 22:57
1  
Which one do you want to remove: the listing or the figure caption? Would you be able to provide a minimal working example (MWE) of your current setup? –  Werner Jan 3 '13 at 23:10
    
I want to remove the listing entry. Just provided a MWE. I decided to put this in a figure also because I used tikz to annote some things in the listing. –  Matthias Jan 3 '13 at 23:25
1  
If you remove the [caption=Listing] option, you don't obtain an entry in the LoL (and that's not a joke)... –  Werner Jan 3 '13 at 23:36
1  
If you want a caption for the Listing but not an entry in the LoL, you can try the environment option nolol: \begin{lstlisting}[caption=Listing,nolol]. Or: \begin{lstlisting}[caption={[]Listing}] which hides the Listing number and doesn’t produce a LoL entry. –  Qrrbrbirlbel Jan 3 '13 at 23:46

1 Answer 1

up vote 5 down vote accepted

As we already figured out in a lengthy comment discussion:

  • ToC: Table of Contents (\tableofcontents)
  • LoF: List of Figures (\listoffigures)
  • LoL: List of Listings (\listoflistings)

Either way, you are looking for the lstlistings option nolol.

If you additionally want no Listings number to be applied you have to use caption={[]<caption>} (with or without nolol).

Reference

Not related, but noteworthy

Your \parbox exceeds the line width by 6pt. (You get a overfull hbox message!) The reason is that the \parbox has a small paddings to its contents, 3pt on each side (even vertically). This is removed by using \linewidth-2\fboxsep in the definition.

And as you may have noticed, I also changed \textwidth to \linewidth.

References

Code

\documentclass{article}
\usepackage{caption}
\usepackage{tikz}
\usepackage{listings}

\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
  \parbox{\textwidth}{\colorbox{gray}{\parbox{\dimexpr\linewidth-2\fboxsep\relax}{\bf\sffamily\small #1#2#3}}\vskip-1pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}

\begin{document}
\tableofcontents \lstlistoflistings \listoffigures
\begin{figure}
\begin{lstlisting}[caption=Listing,nolol]

\end{lstlisting}
\caption{Figure}
\end{figure}
\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.