[Tex/LaTex] How to remove “Listing #: ” from listings caption

captionslistings

I am working on a C++ reference manual for myself and I want good-looking listings.

The Stack Overflow question entitled LaTeX source code listing like in professional books was very helpful but, for the life of me, I can't find anywhere on the Internet how to remove the "Listing #" part of the listing captions.

Below is a screenshot of what I have at the moment. I want to remove the front part of the listing caption; I don't want to remove the caption altogether, though, because I want to use it to show the name of the source file. Any ideas?

enter image description here

Best Answer

Use title instead of caption in the optional argument of the lstlisting environment. See p. 32 of the listings documentation for details.

\documentclass{article}

\usepackage{listings}

\begin{document}

\begin{lstlisting}[caption=foo]
#include <iostream>
\end{lstlisting}

\begin{lstlisting}[title=foo]
#include <iostream>
\end{lstlisting}

\end{document}
Related Question