![如何从第一行开始每隔一行设置 fancyvrb 编号?](https://linux22.com/image/288745/%E5%A6%82%E4%BD%95%E4%BB%8E%E7%AC%AC%E4%B8%80%E8%A1%8C%E5%BC%80%E5%A7%8B%E6%AF%8F%E9%9A%94%E4%B8%80%E8%A1%8C%E8%AE%BE%E7%BD%AE%20fancyvrb%20%E7%BC%96%E5%8F%B7%EF%BC%9F.png)
以下 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}