Displaying listings in LaTeX beamer slides

This post is very old. Please bear in mind that information here might be incorrect or obsolete, and links can be broken. If something seems wrong, please feel free to comment or contact me and I'll update the post.

If you are using LaTeX for presentations, you usually use the Beamer package. If you are serious about listing, you probably use the Listings package — but what if you want nice code listings in a presentation?

Actually, it’s quite easy, all you need is:

\begin{frame}[fragile]
\frametitle{Your title}

\begin{lstlisting}
code
\end{lstlisting}
\end{frame}

That’s it, and you can use all fancy formatting options inside your slides (boxes, shadows, line-numbers, etc.). Just make sure you don’t use the short-hand \frame{ ... } and that you add the [fragile] to each slide that contains a listing.

Related posts:

  1. LaTeX and packages
  2. AMD GDC 2009 slides are available

This entry was posted in General and tagged . Bookmark the permalink.

13 Responses to Displaying listings in LaTeX beamer slides

  1. Pingback: MartyWiki: LaTeX HOWTO

  2. Emerson says:

    Thanks for this tip!

  3. Marcelo says:

    Great Tip!

  4. Ruf says:

    Thank You! Your post is very useful!

  5. Daniel Duque says:

    Great tip! I was going nuts!

  6. rajbabu says:

    thanks for the tip.

  7. misof says:

    nice, thanks!

  8. kit says:

    Thanks so much for this! Now if only the listings package supported JavaScript…

  9. Anteru says:

    You can probably take C and add a bunch of keywords. Creating “derived” languages with lstlistings is comparatively easy.

  10. Olf says:

    The ‘[fragile]‘ hint saved me a lot of hassle :)

  11. Dominic says:

    Great ! Thanks. Never knew about the fragile keyword

  12. René says:

    thx :) works fine

  13. jh says:

    thx, you saved my day

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>