我想知道如何在 Beamer 中获取自动连续示例计数器。以下是我的 MWE。感谢您的帮助。
\documentclass{beamer}
\usetheme{Warsaw}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\begin{document}
\begin{frame}
\begin{example}
This is a test example
\end{example}
\end{frame}
\begin{frame}
\setcounter{example}{2}
\begin{example}
Continued previous example.
\end{example}
\end{frame}
\end{document}
更新
我正在寻找像这样的示例计数器的自动延续在 Beamer 中继续枚举计数器。 谢谢
答案1
定义“延续示例”环境:
\documentclass{beamer}
\usetheme{Warsaw}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\newenvironment{example*}
{\addtocounter{theorem}{-1}\example}
{\endexample}
\begin{document}
\begin{frame}
\begin{example}
This is a test example
\end{example}
\end{frame}
\begin{frame}
\begin{example*}
Continued previous example.
\end{example*}
\end{frame}
\begin{frame}
\begin{example*}
Continued previous example.
\end{example*}
\begin{example}
New example.
\end{example}
\end{frame}
\end{document}
答案2
以下是egreg 的回答允许在常规示例流之间混合“连续示例”。我不认为这是一个有效的用例,因为连续示例通常会从一张幻灯片/frame
到下一张幻灯片一个接一个地出现,但它可能在更大的背景下发挥一些作用:
\documentclass{beamer}% http://ctan.org/pkg/beamer
\usetheme{Warsaw}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\makeatletter
\def\@firstoffive#1#2#3#4#5{#1}%
\newenvironment{example*}[1][\relax]
{\begingroup\ifx#1\relax% No optional argument
\else% Optional argument given
\@ifundefined{r@#1}{}{%
\protected@edef\cont@example@num{\csname r@#1\endcsname}%
\expandafter\edef\expandafter\cont@example@num\expandafter
{\expandafter\@firstoffive\cont@example@num}%%
\renewcommand{\thetheorem}{\cont@example@num}}%
\fi\addtocounter{theorem}{-1}% Revert to previous theorem count
\example}
{\endexample\endgroup}
\makeatother
\begin{document}
\begin{frame}
\begin{example}
This is a test example.
\end{example}
\begin{example*}
This one continues.
\end{example*}
\begin{example}
Another example.\label{myexample}
\end{example}
\end{frame}
\begin{frame}
\begin{example}
This is a test example.
\end{example}
\begin{example*}[myexample]
Continued previous example.
\end{example*}
\begin{example}
Another new example.
\end{example}
\end{frame}
\end{document}
继续示例环境example*
现在带有一个可选参数,该参数应包含对\label
示例中应继续的集合的引用。如果没有给出参数,example*
则按预期运行并继续前一个example
。
答案3
尝试覆盖:
\documentclass{beamer}
\usetheme{Warsaw}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\begin{document}
\begin{frame}
\only<1>{ \begin{example}
This is a test example
\end{example}
}
\only<2>{
\begin{example}
Continued previous example.
\end{example}}
\begin{example}
Another previous example.
\end{example}
\end{frame}
\begin{frame}
\begin{example}
Another previous example.
\end{example}
\end{frame}
\end{document}
只是我看不到 1.1,只能看到 1,正如您在评论中所说。所以您可能使用了其他代码?
2号
保存计数器,并将计数器设置为保存的值。用法:smyex
是父级,而emyex
是具有相同编号的子级,直到下次使用smyex
。希望这就是您对自动化的理解。
\documentclass{beamer}
\usetheme{Warsaw}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\newcounter{extemp}
\newcounter{restoretemp}
\newenvironment{smyex}{\setcounter{extemp}{\theexample}\begin{example}}%
{ \end{example}}
%
\newenvironment{emyex}{%
\setcounter{restoretemp}{\thetheorem}
\setcounter{theorem}{\theextemp}
\begin{example}%
}{\end{example}\setcounter{theorem}{\therestoretemp}
}
\begin{document}
\begin{frame}
\begin{example}
This is a test example
\end{example}
\begin{smyex}
Previous example.
\end{smyex}
\begin{example}
Another previous example.
\end{example}
\end{frame}
\begin{frame}
\begin{example}
This is a test example
\end{example}
\begin{emyex}
Continued previous example
\end{emyex}
\begin{example}
Another previous example.
\end{example}
\end{frame}
\end{document}