semiverbatim 内部的 lstlisting 问题

semiverbatim 内部的 lstlisting 问题

我从中获得的代码这里...

当我运行它时,输出的行号被破坏,比如说 1,然后从 3 到 6,然后从 8 到 11...知道为什么吗?

\documentclass{beamer}

\setbeamercovered{transparent}

\usepackage{pxfonts}
\usepackage{listings}

\begin{document}

\lstset{language=python,
        numbers=left,
        numberstyle=\tiny,
        showstringspaces=false,
        aboveskip=-40pt,
        frame=leftline
        }

\begin{frame}[fragile]
\frametitle{\texttt{parrot.py}}
\begin{semiverbatim}
\pause
\begin{lstlisting}
if __name__ == "__main":

\end{lstlisting}

\pause
\begin{lstlisting}[firstnumber=last]
    print "Oh yes, the, uh,
           the Norwegian Blue..."
    print "What's, uh...
           What's wrong with it? "

\end{lstlisting}

\pause
\begin{lstlisting}[firstnumber=last]
    print "I'll tell you what's wrong with it,
           my lad."
    print "'E's dead,
           that's what's wrong with it!"

\end{lstlisting}
\end{semiverbatim}
\end{frame}

\end{document

答案1

这些列表中有空行。每个空行都分配有一个行号,但不会打印该行号。尝试:

\documentclass{beamer}

\setbeamercovered{transparent}

\usepackage{pxfonts}
\usepackage{listings}

\begin{document}

\lstset{language=python,
        numbers=left,
        numberstyle=\tiny,
        showstringspaces=false,
        aboveskip=-40pt,
        frame=leftline
        }

\begin{frame}[fragile]
\frametitle{\texttt{parrot.py}}
\begin{semiverbatim}
\pause
\begin{lstlisting}
if __name__ == "__main":
\end{lstlisting}

\pause
\begin{lstlisting}[firstnumber=last]
    print "Oh yes, the, uh,
           the Norwegian Blue..."
    print "What's, uh...
           What's wrong with it? "
\end{lstlisting}

\pause
\begin{lstlisting}[firstnumber=last]
    print "I'll tell you what's wrong with it,
           my lad."
    print "'E's dead,
           that's what's wrong with it!"
\end{lstlisting}
\end{semiverbatim}
\end{frame}

\end{document}

在此处输入图片描述

相关内容