I am using the listings
package to include source code in my .tex
-document. Now I would like to reference to these lstinputlisting
s. Therrefore, I am using this
lstinputlisting[label=lst:mat.h, title=\textbf{src:} mat.h]{src/mat.h}
to include the file and
\ref{list:mat.h}
to reference to it. Now I do not get an error message, but instead of a number to this listing I only get the number of the (sub)section.
Is there any way to solve this problem?
Best Answer
Without using the
caption
option, the\label
applies the\@currentlabel
settings which has been modified by the last\refstepcounter
, apparently in the OP this was some\subsection
operation.Solution: Apply
caption=...
as an option in the optional argument of\lstinputlisting
-- this will print the listing number as well and adds the listing to theList of Listings
.The
hellowordexample.c
is very short, but sufficient for testing: