我想知道是否可以结合 listings 包设置自定义行号。请参阅下面的 MWE。我只希望最后一行(编号为 8)显示为例如编号 500。如果不使用 listings,您还有其他建议吗?
谢谢并致以最诚挚的问候
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[basicstyle=\ttfamily, frame=single, columns=fullflexible, keepspaces=true, numbers=left, stepnumber=1]
Record Length,2.500000e+03,, -0.001250000000, -0.76000,
Sample Interval,1.000000e-06,, -0.001249000000, -0.74000,
,,,-00.001225000000, -0.64000,
,,,-00.001224000000, -0.62000,
...
,,,00.001249000000, 0.78000,
\end{lstlisting}
\end{document}
答案1
\documentclass{article}
\usepackage{listings}
\begin{document}
{\renewcommand\thelstnumber{%
\ifnum\value{lstnumber}=8 5000\else\arabic{lstnumber}\fi}
\begin{lstlisting}[basicstyle=\ttfamily, frame=single,
columns=fullflexible, keepspaces=true, numbers=left, stepnumber=1]
Record Length,2.500000e+03,, -0.001250000000, -0.76000,
Sample Interval,1.000000e-06,, -0.001249000000, -0.74000,
,,,-00.001225000000, -0.64000,
,,,-00.001224000000, -0.62000,
...
,,,00.001249000000, 0.78000,
\end{lstlisting}}
\end{document}