Using the verbatim Environment and listings Package with Beamer

August 13, 2008 at 10:11 PM | categories: LaTeX, tips | View Comments

I finally figured out how to make the verbatim environment work with Beamer. Beamer can't handle the following code:

\begin{frame}{A Title}
    \begin{verbatim}
    Don't mess with my text.
    \end{verbatim}
\end{frame}

To make it work, you need to include the fragile option for the frame. Example:

\begin{frame}[fragile]{A Title}
    \begin{verbatim}
    Don't mess with my text.
    \end{verbatim}
\end{frame}

If you use the listings package, the same trick works for the lstlistings environment.