tags:

views:

1094

answers:

4

Hello,

I have a latex document with a bunch of verbatim text. I would like to indent every single instance of these.

For example:

This is regular text.
\begin{verbatim}
This is verbatim text.
\end{verbatim}

I want "This is verbatim text" to be indented a centimeter or two. How do I do this?

A: 

You could define a new command that indents how you like.

Something like this:

\newcommand{\myverb}[1]{ \indent{ \begin{verbatim} #1 \end{verbatim} } }

This should let you do:

\myverb{ This is verbatim text. }
Brian Gianforcaro
No way just to set something in the header of the document?
carl
@cvondrick I don't think so, but you could define your own class. That's much harder than what Brian is suggesting though.
Pascal Cuoq
agreed. I'll accept this answer unless a better one comes along shortly. Thank you!
carl
Are you able to make this work? LaTeX doesn't seem to like `\end{verbatim}` inside a `\newcommand` definition. As posted here, I get a compilation error.
ezod
Yeah, I don't believe this solution works. Verbatim cannot go inside newcommand. See my answer to a related question here: http://stackoverflow.com/questions/2121035/how-do-i-create-a-new-beamer-environment-with-a-verbatim-environment/2126150#2126150
Steve
+2  A: 

You could wrap all your verbatim environments in quote environments:

\begin{quote}
\begin{verbatim}
This is indented verbatim text.
Works for multiple lines, too.
\end{verbatim}
\end{quote}
ezod
+2  A: 

This extends ezod's answer above.

\documentclass{article}
\usepackage{fancyvrb}
\newenvironment{qv}
{\quote\Verbatim}
{\endquote\endVerbatim}
\begin{document}
\begin{qv}
This text
is indented.
\end{qv}
\end{document}
Steve
A: 

Any indent

\catcode`\@=11
\let \saveverbatime \@xverbatim
\def \@xverbatim {\leftskip = 1cm\relax\saveverbatime}
\catcode`\@=12
Alexey Malistov