# Doesn't the verbatim environment work with the standalone class?

I have the following code, which is as minimal as it could possibly be ( standalone 2015/07/15 v1.2):

\documentclass{standalone}

\begin{document}
\begin{verbatim}
Ciao
\end{verbatim}
\end{document}


And I get the error:

! LaTeX Error: Something's wrong--perhaps a missing \item.


If I replace the standalone class with another class, e.g. article, everything works fine.

Where's the issue?

Try

\documentclass[preview]{standalone}% <-- added option "preview"

\begin{document}
\begin{verbatim}
Ciao
\end{verbatim}
\end{document}


This should work ...

Edit: Also work with option varwidth. Both options enable to show verbatim environments and as well as displayed math. This is not special described in standalone manual, but seems that for text elements/environments, which normally occupy whole text line, it is obligatory to select appropriate standalone's options.

• Care to explain why is an optional argument mandatory? – Matsmath May 5 '16 at 7:33
• @Matsmath, done. – Zarko May 5 '16 at 8:08

The verbatimbox package allows inline verbatim environments that work directly with the standalone class. Once the box is created with the verbbox environment, it is displayed with \theverbbox.

\documentclass{standalone}
\usepackage{verbatimbox}
\begin{document}
\begin{verbbox}
Ciao
\end{verbbox}
\theverbbox
\end{document}


Example 2 (longer code and optional argument):

\documentclass{standalone}
\usepackage{verbatimbox}
\begin{document}
\begin{verbbox}[\scshape]
This is code line 1
Blah
Blah-blah
Finis
\end{verbbox}
\theverbbox
\end{document}