以下 MWE 使用fancyvrb
从第二行开始每隔一行产生行号,如下所示:
Writing some test
2
third line
4 fourth line
fifth line
所以数字是2, 4, 6,...
。我希望数字从第一行开始,然后每隔一行,例如:
1 Writing some test
3 third line
fourth line
5 fifth line
我怎样才能实现这个目标?
梅威瑟:
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\begin{Verbatim}[numbers=left,firstnumber=1,stepnumber=2]
Writing some test
third line
fourth line
fifth line
\end{Verbatim}
\end{document}
答案1
您可以尝试这个小技巧。在源代码开头添加一个空行,然后使用firstline=2
它跳过该行。我附上了一个示例和预览。
% run: *latex mal-fancyvrb.tex
\documentclass{article}
\pagestyle{empty}
\parindent=0pt
\usepackage{fancyvrb}
\begin{document}
Text before.
\begin{Verbatim}[numbers=left, firstnumber=1, stepnumber=2, firstline=2]
Writing some test
third line
fourth line
fifth line
\end{Verbatim}
Text after.
\end{document}