53

I'm trying to add some code in a presentation made with LaTex. I used beamer, added some frames without problems but once I add the listing, I can't compile the presentation anymore.

\begin{frame}{Code}
\begin{lstlisting}
Sample Code
\end{lstlisting}
\end{frame}

The error I pdflatex gave me is:

Package Listings Warning: Text dropped after begin of listing on input line 80.

Is there anything special to add to make it work ?

Jf Beaulac
  • 5,206
  • 1
  • 25
  • 46
Thomas Schwery
  • 795
  • 1
  • 7
  • 9

3 Answers3

76

Try making a fragile frame:

\begin{frame}[fragile]
drs
  • 5,679
  • 4
  • 42
  • 67
  • No sorry, it doesn't compile either. Still the same error. :-( – Thomas Schwery Jun 05 '10 at 16:38
  • Strange, I cannot reproduce your behaviour. I guess really long lines in the listing could break it. Other culprits may be the theme used with beamer or packages not installed properly. –  Jun 05 '10 at 18:15
  • 12
    Sorry, it works, I retried it : You have to add the [fragile] before the title : \begin{frame}[fragile]{Frame Title} – Thomas Schwery Jun 05 '10 at 20:28
30

The fragile option didn't work for me, but this did:

\begin{frame}[containsverbatim]
drs
  • 5,679
  • 4
  • 42
  • 67
Gero
  • 400
  • 3
  • 5
  • 4
    you saved my day! Is this a change in a recent beamer version? Should be better documented! – thias Mar 23 '15 at 08:28
  • `fragile` has been the right name for _many_ years: you must have an _ancient_ version of `beamer` if you have to use `containsverbatim` – Joseph Wright Oct 23 '18 at 06:39
  • 3
    With the latest version of everything at the present date (2021), [fragile] sometimes works, often breaks, whereas [containsverbatim] seems to be the right way to go! – Dalker Jun 20 '21 at 09:22
  • @Dalker: Support your comment! Fragile produces an error when include listing containing frame environment. – Say OL Oct 29 '21 at 15:44
2

listings provides frame functions:

\begin{lstlisting}[frame=single]
Sample Code
\end{lstlisting}
msrd0
  • 7,816
  • 9
  • 47
  • 82
david villa
  • 384
  • 4
  • 9