[Tex/LaTex] How to indent verbatim blocks

verbatim

I have blocks surrounded by \begin{verbatim} and \end{verbatim}. I'd like to indent these about half an inch. I'm using pandoc to write pdfs via XeLaTeX and the default.latex pandoc template, so I'd like not to create a new environment, but to revise the behavior of verbatim in default.latex so that it is indented a little.

Best Answer

The package fancyvrb has the enhanced Verbatim environment, and the key xleftmargin:

\documentclass{article}
\usepackage{fancyvrb}

\begin{document}
\thispagestyle{empty}

\noindent A non-verbatim line
\begin{Verbatim}[xleftmargin=.5in]
Some verbatim
lines
\end{Verbatim}
\noindent Another line
\end{document}

enter image description here

Moreover, you can redefine the standard verbatim like this:

\documentclass{article}
\usepackage{fancyvrb}

\DefineVerbatimEnvironment{verbatim}{Verbatim}{xleftmargin=.5in}

\begin{document}
\thispagestyle{empty}
\noindent A non-verbatim line
\begin{verbatim}
Some verbatim
lines
\end{verbatim}
\noindent Another line
\end{document}

This gives the same result as above