19

What's the best way to include some code snippets in a beamer presentation?

I've already tried verbatim, and lstlisting environments - both destroyed my presentation.

jopasserat
  • 5,721
  • 4
  • 31
  • 50
mik01aj
  • 11,928
  • 15
  • 76
  • 119

2 Answers2

25

Use the [fragile] option:

\begin{frame}[fragile]
\begin{verbatim}
...
\end{verbatim}
\end{frame}
mkluwe
  • 3,823
  • 2
  • 28
  • 45
  • I've already tried this, with a strange result. The slide with code looks OK, but all slides before have paper size changed to A4. – mik01aj Nov 08 '09 at 21:42
  • That is *very* strange indeed, as the "paper size" should be 128mm times 96mm to reflect the 4:3 ratio of most beamers output. You didn't fiddle around with that setting, did you? – mkluwe Nov 09 '09 at 16:55
3

I recently used something like

\verbatiminput{blah.c}

in a beamer presentation, and it worked alright for me...

Wanna post your code?

freedrull
  • 2,194
  • 4
  • 21
  • 33