I want to cross-reference a listing item. I used the label in the \lstinputlisting
, but the output shows ??
. Here is the script:
\documentclass{article}
\usepackage{lipsum}
\usepackage{cleveref}
\usepackage{listings}
\usepackage{xcolor}
\begin{document}
\title{Test}
\maketitle
\section{Listing}
\lstset{language=Python}\label{ls:example}
\lstinputlisting[language=Python, label=my_listing_label, caption={caption.}]{/home/e/Documents/test_latex/test.py}
\section{Another Section}
We reference~\cref{my_listing_label}
\end{document}
Here is the test.py
content:
if x==y:
print("hi")
EDIT: Also, I need to add that I want the cross-referencing displayed as listing 1 not as section 1.