逐字逐句和叠加

逐字逐句和叠加

我正在尝试verbatim在覆盖层中显示环境。我有以下代码,但它给出了错误:

\only<2->{
\begin{verbatim}
Select T3.Subject
From  T as T1, T as T2, T as T3
Where T1.Predict=“BornOnDate” and
T1.Object=“1809-02-12” and 
T2.Predict=“DiedOnDate” and 
T2.Object=“1865-04-15” and 
T3. Predict=“hasName” and 
T1.Subject = T2.Subject and 
T2. Subject= T3.subject 
\end{verbatim}
}

有人能指出我做错什么吗?

答案1

宏参数中不允许使用逐字材料,因为在verbatim处理之前会读取完整参数。到那时,所有文本都已在内部转换,即所有文本\abcd都已是宏,所有文本%text都已删除等。

因为frame实际上是一个伪环境,它像宏一样读取其内容,所以您需要使用其fragile选项来特别注意逐字和类似内容。但是,您仍然不允许在宏的参数中使用它。我会将它存储在一个盒子寄存器中并在里面使用它\only。出于某种原因,这不适用于verbatim环境,但适用lstlistinglisting包。您可以并且也应该将材料装箱在外面frame,那么您不需要该fragile选项。

\documentclass{beamer}
\newsavebox{\mysavebox}
\usepackage{listings}


\begin{document}

\begin{lrbox}{\mysavebox}
\begin{lstlisting}
Select T3.Subject
From  T as T1, T as T2, T as T3
Where T1.Predict="BornOnDate" and 
T1.Object="1809-02-12" and
T2.Predict="DiedOnDate" and
T2.Object="1865-04-15" and 
T3. Predict="hasName" and
T1.Subject = T2.Subject and 
T2. Subject= T3.subject
\end{lstlisting}
\end{lrbox}

\begin{frame}{Some title}
\only<2->{\usebox{\mysavebox}}
\end{frame}

\end{document}

答案2

verbatim只能通过宏来实现\defverbatim。但是,verbatim你应该使用包listings。可以用同样的方式完成。如果你需要它有颜色,那么使用\defverbatim[colored]{...}

\documentclass{beamer}      
\begin{document}

\defverbatim{\foo}{%
\begin{verbatim}
Select T3.Subject
From  T as T1, T as T2, T as T3
Where T1.Predict=“BornOnDate” and 
T1.Object=“1809-02-12” and
T2.Predict=“DiedOnDate” and
T2.Object=“1865-04-15” and 
T3. Predict=“hasName” and
T1.Subject = T2.Subject and 
T2. Subject= T3.subject
\end{verbatim}
}

\begin{frame}{Some title}
\only<2->{\foo}
\end{frame}
\end{document}

答案3

使用onlyenv环境而不是\only命令可以有所帮助,正如指出的那样https://tex.stackexchange.com/a/274725/15107

相关内容