\lstinputlisting에 대한 참조가 작동하지 않습니다.

\lstinputlisting에 대한 참조가 작동하지 않습니다.

내가 뭔가 잘못하고 있는 것일 수도 있지만 무엇인지는 알 수 없습니다...

다음과 같이 표시되는 코드 조각에 대한 레이블을 설정하고 싶습니다.

\lstinputlisting[language=Python, label={lst:control_os_call}, firstline=231, lastline=257]{./code/server.py}

그래서 그냥 \ref를 사용하여 연결하려고 합니다.

\ref{lst:control_os_call}

하지만 항상 라벨 누락 오류가 발생합니다( 의 라벨에만 해당 \lstinputlisting). 그럼... 그런 종류의 라벨을 참조하기 위해 특정 패키지를 가져와야 할까요? 아니면 제가 뭘 잘못하고 있는 걸까요?

정말 감사합니다 :)

답변1

caption그게 전부 입니다 .

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{server.py}
This is some python code
\end{filecontents*}

\usepackage{listings}
\lstset{basicstyle=\ttfamily}

\begin{document}
\lstinputlisting[language=Python,caption={some python code}, label={lst:control_os_call}, firstline=1, lastline=257]{server.py}

Here is the code~\ref{lst:control_os_call}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보