7

Line numbers generated for verbatim text by the fancyvrb package are put outside the verbatim environment:

\documentclass{article}   
\usepackage{fancyvrb}

\begin{document}
\begin{Verbatim}[numbers=left]
First verbatim line.
Second verbatim line.
\end{Verbatim}
Normal text
\end{document}

Output

How do I align the numbering in such a way that they are inside the verbatim environment (left aligned with "normal text") and don't go into the page margin?

Thanks

2 Answers 2

9

Use xleftmargin:

\documentclass{article}   
\usepackage{fancyvrb}

\begin{document}
\begin{Verbatim}[numbers=left,xleftmargin=5mm]
First verbatim line.
Second verbatim line.
\end{Verbatim}
Normal text
\end{document}

enter image description here

5

Just for completeness, the verbatimbox package can also do this with its optional argument. In this case, I am using the verbnobox environment.

\documentclass{article}
\usepackage{verbatimbox}
\begin{document}
\def\verbarg{{\scriptsize\makebox[2ex]{\arabic{VerbboxLineNo}}}\hspace{2ex}}
\begin{verbnobox}[\verbarg]
First verbatim line.
Second verbatim line.
\end{verbnobox}
Normal text
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .