GeneralListings Package Question

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
gkl
Posts: 28
Joined: Sat Jan 17, 2009 12:21 am

Listings Package Question

Post by gkl »

Dear All,

I am writing my PhD thesis and I need to quote a few code snippets. Some of them I want them not to have captions, so in my \begin{lstlisting} directive there is no caption parameter.

However, when I need to reference them I found that it is not possible without a caption. As an example, if you have a listing like the following:
\begin{lstlisting}[label=lis:hw]
printf("Hello World!\n");
\end{lstlisting}

If later on, you write something like listing~\ref{lis:hw}, this will produce the section number and not the value of the listings counter.

Is there any cure for that?

Regards,
George

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply