# Exclude listings from LoL

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}

-
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 at 22:57
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 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 at 23:25
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 at 23:36
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 at 23:46

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).

## 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.

## 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}

-