# listings ignore final newline

When I write listings in my LaTeX code I usually follow this format

\begin{lstlisting}
foo
bar
baz
\end{lstlisting}


and when I put this inside a normal LaTeX document, things look fine. But when I put this inside a beamer block, there is an extra line that is included at the end and I need to do

\begin{lstlisting}
foo
bar
baz\end{lstlisting}


to get it to look right. Is there any way to tell listings to ignore the final newline?

-

## migrated from stackoverflow.comMay 31 '12 at 16:44

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Werner May 31 '12 at 16:46
Could you provide a small (minimal) example that highlights this? Also include the versions of the files your using. Do so by adding \listfiles to your document preamble and including the contents after *File List* in your .log file. –  Werner May 31 '12 at 16:48
It works for me with last beamer version and Warsaw theme. Remember that you must use \begin{frame}[fragile] to include verbatim code. –  Ignasi Jun 1 '12 at 7:13

To remove this question from the unanswered list

Your effect can't be reproduced. The example below results in the following frame:

You can see there isn't any additional line. Please note if you use the environment lstlisting inside a beamer frame -- the environment frame needs the option fragile. For more information consult the documentation of beamer.

\documentclass{beamer}
\usepackage{listings}
\lstset{frame=single}
\begin{document}
\begin{frame}[fragile]
Text
\begin{lstlisting}
foo
bar
baz
\end{lstlisting}
Text
\end{frame}
\end{document}

-