为此我使用以下内容:
\lstset{language= python, breaklines=true,basicstyle=\footnotesize}
\lstset{numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt}
和
\begin{lstlisting}[frame=single]
sage: s0.series(z,6)
1 + 1*z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5 + Order(z^6)
\end{lstlisting}
\begin{lstlisting}[frame=single]
sage: s1.series(z,6)
1*z^(-1) + (-1) + (-1)*z + (-2)*z^2 + (-5)*z^3 + (-14)*z^4 + (-42)*z^5 + Order(z^6)
\end{lstlisting}
我正在寻找的是第二个框左侧的数字从 3 开始计数(因为它是第三行),并且如您所见,它从 1 开始,就像在第一个框中一样。有人知道如何解决这个问题吗?
答案1
为参数使用一个明确的值firstnumber
,或者选择last
是否要继续编号。
\documentclass{article}
\usepackage{listings}
\usepackage{xfp,refcount}
\lstset{
language=python,
breaklines=true,
basicstyle=\footnotesize,
numbers=left,
numberstyle=\tiny,
stepnumber=1,
numbersep=5pt
}
\begin{document}
\begin{lstlisting}[frame=single]
sage: s0.series(z,6)
1 + 1*z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5 + Order(z^6)
\end{lstlisting}
% firstnumber set to an explicit fixed value
\begin{lstlisting}[frame=single,firstnumber=3]
sage: s1.series(z,6)
1*z^(-1) + (-1) + (-1)*z + (-2)*z^2 + (-5)*z^3 + (-14)*z^4 + (-42)*z^5 + Order(z^6)
\end{lstlisting}
% firstnumber set to continue from the last value
\begin{lstlisting}[frame=single,firstnumber=last]
sage: s3.series(z,6)
1 + 1*z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5 + Order(z^6)
\end{lstlisting}
\end{document}