LaTex,Beamer和Listings的问题

54

我正在尝试在使用LaTex制作的演示文稿中添加一些代码。 我使用了beamer,在没有问题的情况下添加了一些帧,但是一旦我添加了列表,就再也无法编译演示文稿。

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

我收到的pdflatex错误信息是:

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

有没有什么特别的内容需要添加,使其能够工作?

3个回答

77

试着创建一个脆弱的框架:

\begin{frame}[fragile]

不好意思,它仍然无法编译。错误还是一样的。 :-( - Thomas Schwery
奇怪,我无法复制你的行为。我猜测在列表中有太长的行可能会破坏它。其他罪魁祸首可能是与 beamer 使用的主题或未正确安装的包。 - user110763
12
抱歉,它能够正常工作,我重新尝试了一下:您需要在标题前添加 [fragile] : \begin{frame}[fragile]{帧标题} - Thomas Schwery

32

fragile 选项对我不起作用,但是这个可以:

\begin{frame}[containsverbatim]

4
你救了我的一天!这是最近Beamer版本的更改吗?应该有更好的文档记录! - thias
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
3
截至2021年最新版本,[fragile]有时有效,常常会出现问题,而[containsverbatim]似乎是正确的选择! - Dalker
@Dalker:支持你的评论!当包含帧环境的列表被包含时,Fragile会产生错误。 - Say OL

2

listings 提供框架函数:

\begin{lstlisting}[frame=single]
Sample Code
\end{lstlisting}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接