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

share|improve this question
    
Welcome on StackExchange! I've embedded the screenshot for you, which you'll be able to do yourself once you reach 10 reputation (almost there!). –  Jake Feb 16 '11 at 22:56
    
See also: stackoverflow.com/questions/741985/… –  Dave Jarvis Feb 17 '11 at 3:20
add comment

2 Answers

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

The approach proposed by lockstep is straighforward, but your listings won't appear in the List of Listings if you follow it. If you want to avail of \lstlistoflistings, you'll need to use the caption key, not the title one.

In order not to print "Listing #: " in captions, simply remove #1#2 from the third argument of \DeclareCaptionFormat in the code from the accepted answer to the SO question entitled LaTeX source code listing like in professional books.

enter image description here

\documentclass{report}

\usepackage{color}
\usepackage{xcolor}
\usepackage{listings}

\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}

\begin{document}

\lstlistoflistings

\begin{lstlisting}[label=some-code,caption=Some Code]
public void here() {
    goes().the().code()
}
\end{lstlisting}

\end{document}
share|improve this answer
add comment

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.