General ⇒ What difference is there between caption and title in lstlisting in latex?
What difference is there between caption and title in lstlisting in latex?
I can see the title on the output pdf. I do not see the label anywhere though. What is the lstlisting label used for?
Thanks
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
-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
What difference is there between caption and title in lstlisting in latex?
The "label" is how you refer to the caption number in the text (as "\label" won't work inside a verbatim environment). Observe:
Code: Select all
\documentclass{article}
\usepackage{listings}
\begin{document}
%\begin{lstlisting}[title={this is the title},label={hello}]
\begin{lstlisting}[caption={this is a caption},label={hello}]
This is code
# Commented
# etc.
if ( 5 > 3 ) print "hello"
\end{lstlisting}
The listing above is Code sample~\ref{hello}.
\end{document}