[Tex/LaTex] Shift Verbatim environment to the left using \hspace

fancyvrbhorizontal alignmentindentation

I pasted some code into a document in a Verbatim environment from fancyvrb. Because it is within two nested enumerate environments, the code is indented quite far over. As a result, one long line of code extends off the page. The quickest fix that I could think of was to place a \hspace command with a negative argument just before the Verbatim environment in order to shift the whole Verbatim environment over to the left a few cm. However, this had no effect. Can someone suggest a solution please? See MWE below.

\documentclass{article}
 \usepackage{fancyvrb}
 \begin{document}
 \begin{enumerate}
  \item First item
  \begin{enumerate}
   \item First sub-item

   \hspace{-5cm}\begin{Verbatim}[fontsize=\tiny]
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
   \end{Verbatim}
  \end{enumerate}
 \end{enumerate}
\end{document} 

Best Answer

Here's a solution with the verbatimbox package. Note that this first solution will not break the verbatim across page boundaries.

\documentclass{article}
 \usepackage{verbatimbox}
 \begin{document}
 \begin{enumerate}
  \item First item
  \begin{enumerate}
   \item First sub-item

   \hspace{-5cm}\begin{verbbox}[\tiny]
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
   \end{verbbox}
   \theverbbox
  \end{enumerate}
 \end{enumerate}
\end{document} 

enter image description here

For a solution that can break the verbatim across page boundaries, with the \hspace:

\documentclass{article}
 \usepackage{verbatimbox}
\textheight 1.5in
 \begin{document}
 \begin{enumerate}
  \item First item
  \begin{enumerate}
   \item First sub-item

   \begin{verbnobox}[\tiny\hspace{-4cm}]
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
    This line of code is nice and short and fits nicely on the page.
    This line of code is very long and does not fit onto the page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The End
   \end{verbnobox}
  \end{enumerate}
 \end{enumerate}
\end{document} 
Related Question