beamer
beamer copied to clipboard
Extra vertical space before lstlisting code with latest listings package
After updating listings
package from version 1.6 to 1.7, there was extra vertical space before lstlisting
code.
\documentclass{beamer}
\usepackage{listings}
\begin{document}
\begin{frame}[fragile=singleslide]
\frametitle{Some Title}
\begin{lstlisting}
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
Some Code
\end{lstlisting}
\end{frame}
\end{document}
Please compare the following two results. It is OK with article
class. A bug of beamer
or listings
?
@zohooo The recent change on auto-breaking of frames is in the commit fd369b7. Can you help test it?
I have tried latest code in beamer repository, but didn't fixed this problem.
I comared listings
version 1.6 and 1.7, and found that a \leavevmode
was added to the beginning of lstlisting environment in version 1.7, causing the problem in beamer
frames.
\lstnewenvironment{lstlisting}[2][]
{%
\leavevmode%
\lst@TestEOLChar{#2}%
\lstset{#1}%
\csname\@lst @SetFirstNumber\endcsname}
{\csname\@lst @SaveFirstNumber\endcsname}
I can confirm this.
The \leavevmode
in listings v1.7 was apparently added to fix the problem discussed in https://tex.stackexchange.com/questions/136256/strange-interaction-between-listings-and-sections
(curiously enough, \lstinputlisting
was not changed, so the problem still exists there).
Unfortunately, \leavevmode
in the opening of lstlisting
does add extra vertical space in beamer slides, just as @zohooo observed, breaking a lot of my beamer presentations.
As a workaround, I can simply use a patched local copy of listings.sty
with \leavevmode
removed. However, it would be nice if beamer could somehow restore the previous behaviour.
@tertium You could also use \lstnewenvironment
to define your own listing environments. These environments work as before, without extra vertical space.