josephwright / beamer

A LaTeX class for producing presentations and slides
Other
1.4k stars 141 forks source link

Extra vertical space before lstlisting code with latest listings package #515

Open zohooo opened 5 years ago

zohooo commented 5 years ago

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?

listings0

listings1

louisstuart96 commented 5 years ago

@zohooo The recent change on auto-breaking of frames is in the commit fd369b7. Can you help test it?

zohooo commented 5 years ago

I have tried latest code in beamer repository, but didn't fixed this problem.

zohooo commented 5 years ago

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}
tertium commented 5 years ago

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.

zohooo commented 5 years ago

@tertium You could also use \lstnewenvironment to define your own listing environments. These environments work as before, without extra vertical space.