如何在 beamer two 列中输入代码

如何在 beamer two 列中输入代码

我试图将代码和图形并排放在beamer演示文稿中。我尝试了两种方法 - 一种在beamer文档中提到,另一种在标准 LaTeX 中提到。但无法获得输出。如果我没有任何代码,两列方法可以很好地工作。我尝试了和listingsverbatimfragile都无济于事。

我给出的代码是

\begin{frame}
\begin{columns}
\column[t]{5cm}
Two
\column[t]{5cm}
test
\end{columns}

效果很好。但是当我给出带有fragile选项的代码时,它给出了错误。没有fragile选项的代码也给出了错误。

\begin[fragile]{frame}
\begin{columns}
\column[t]{5cm}
\begin{verbatim}
Two
\end{verbatim}
\column[t]{5cm}
test
\end{columns}

我收到的错误是(来自日志文件)

 [8
] [9
]
! Missing $ inserted.
<inserted text>
$
l.100
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
! Display math should end with $$.
<to be read again>
\par
l.100
The `$' that I just saw supposedly matches a previous `$$'.
So I shall assume that you typed `$$' both times.
! You can't use `\unskip' in vertical mode.
\beamer@smuggle ...@zeropt \else \ifvmode \unskip
\fi \ifhmode \unskip \fi \...
l.102 \column
[t]{5cm}
Sorry...I usually can't take things from the current page.
Try `I\vskip-\lastskip' instead.
! Extra }, or forgotten \endgroup.
\endframe ->\egroup
\begingroup \def \@currenvir {frame}
l.110 \end{frame}
I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.
[10
]
\tf@nav=\write6
\openout6 = `latex.nav'.
\tf@toc=\write7
\openout7 = `latex.toc'.
\tf@snm=\write8
\openout8 = `latex.snm'.
! LaTeX Error: \begin{equation*} on input line 88 ended by \end{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

我也遇到了没有代码的错误,包括脆弱选项。我还尝试了以下方法,但无济于事

\begin[fragile]{frame}
\frametitle{Structure of a \LaTeX\ document}
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{semiverbatim}
test
\end{semivrbatim}
\end{column}
\begin{column}{0.5\textwidth}
\includegraphics[scale=.2]{hello}
\end{column}
\end{frame}
\end{columns}

答案1

正确的语法是

\begin{frame}[fragile]

这是您的示例:

\documentclass{beamer}

\begin{document}

\begin{frame}[fragile]
\begin{columns}
\column[t]{5cm}
\begin{verbatim}
Two
\end{verbatim}
\column[t]{5cm}
test
\end{columns}
\end{frame}

\end{document}

在此处输入图片描述

答案2

您的语法不正确:\begin{frame}[fragile],而不是\begin[fragile]{frame}

以下方法有效(即使你verbatimlstlistingfrom替换环境)listings):

在此处输入图片描述

\documentclass{beamer}% http://ctan.org/pkg/beamer
\begin{document}
\begin{frame}[fragile]
  \frametitle{Structure of a \LaTeX\ document}
  \begin{columns}
    \begin{column}{0.5\textwidth}
\begin{verbatim}
test code
here is some more stuff
172 192 d9a $^&2 ()%$
\end{verbatim}
    \end{column}
    \begin{column}{0.5\textwidth}
      \includegraphics[width=.7\linewidth]{example-image-a}
    \end{column}
  \end{columns}
\end{frame}
\end{document}

相关内容