对于定理、引理和定义的不同编号,我参考 这里. 它指出
beamer
使用选项加载notheorems
并“手动”声明所有定理类型,而不引入通用编号方案。(注意:这有点像 hack,因为它会破坏countsect
除 之外的每种类型的包选项 [按节进行定理编号] theorem
。)
\documentclass[notheorems]{beamer}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\makeatletter
\ifbeamer@countsect
\newtheorem{theorem}{\translate{Theorem}}[section]
\else
\newtheorem{theorem}{\translate{Theorem}}
\fi
\newtheorem{corollary}{\translate{Corollary}}
\newtheorem{fact}{\translate{Fact}}
\newtheorem{lemma}{\translate{Lemma}}
\newtheorem{problem}{\translate{Problem}}
\newtheorem{solution}{\translate{Solution}}
\theoremstyle{definition}
\newtheorem{definition}{\translate{Definition}}
\newtheorem{definitions}{\translate{Definitions}}
\theoremstyle{example}
\newtheorem{example}{\translate{Example}}
\newtheorem{examples}{\translate{Examples}}
% Compatibility
\newtheorem{Beispiel}{Beispiel}
\newtheorem{Beispiele}{Beispiele}
\theoremstyle{plain}
\newtheorem{Loesung}{L\"osung}
\newtheorem{Satz}{Satz}
\newtheorem{Folgerung}{Folgerung}
\newtheorem{Fakt}{Fakt}
\newenvironment{Beweis}{\begin{proof}[Beweis.]}{\end{proof}}
\newenvironment{Lemma}{\begin{lemma}}{\end{lemma}}
\newenvironment{Proof}{\begin{proof}}{\end{proof}}
\newenvironment{Theorem}{\begin{theorem}}{\end{theorem}}
\newenvironment{Problem}{\begin{problem}}{\end{problem}}
\newenvironment{Corollary}{\begin{corollary}}{\end{corollary}}
\newenvironment{Example}{\begin{example}}{\end{example}}
\newenvironment{Examples}{\begin{examples}}{\end{examples}}
\newenvironment{Definition}{\begin{definition}}{\end{definition}}
\makeatother
\begin{document}
\begin{frame}
\begin{theorem}[A theorem]
Some text.
\end{theorem}
\begin{definition}[A definition]
Some text.
\end{definition}
\end{frame}
\end{document}
我遇到的问题是使用 \label{eq:abc} 和 \ref{eq:abc} 时。输出中引用显示的编号不正确。我研究了这个问题,似乎它的编号是定理数+定义+引理+1。
我如何获得正确的输出?
答案1
使用共享计数器,如amsthm 手册第 3 章。
在这里,我尽了最大努力安萨兹您想要共享编号的环境。
\documentclass[notheorems]{beamer}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\makeatletter
\newcounter{theoremcnt}
\ifbeamer@countsect
\newtheorem{theorem}[theoremcnt]{\translate{Theorem}}[section]
\else
\newtheorem{theorem}[theoremcnt]{\translate{Theorem}}
\fi
\newcounter{corollarycnt}
\newtheorem{corollary}[corollarycnt]{\translate{Corollary}}
\newcounter{factcnt}
\newtheorem{fact}[factcnt]{\translate{Fact}}
\newcounter{lemmacnt}
\newtheorem{lemma}[lemmacnt]{\translate{Lemma}}
\newcounter{problemcnt}
\newtheorem{problem}[problemcnt]{\translate{Problem}}
\newcounter{solutioncnt}
\newtheorem{solution}[solutioncnt]{\translate{Solution}}
\theoremstyle{definition}
\newcounter{definitioncnt}
\newtheorem{definition}[definitioncnt]{\translate{Definition}}
\newtheorem{definitions}[definitioncnt]{\translate{Definitions}}
\theoremstyle{example}
\newcounter{examplecnt}
\newtheorem{example}[examplecnt]{\translate{Example}}
\newtheorem{examples}[examplecnt]{\translate{Examples}}
% Compatibility
\newtheorem{Beispiel}[examplecnt]{Beispiel}
\newtheorem{Beispiele}[examplecnt]{Beispiele}
\theoremstyle{plain}
\newtheorem{Loesung}[solutioncnt]{L\"osung}
\newtheorem{Satz}[theoremcnt]{Satz}
\newtheorem{Folgerung}[lemmacnt]{Folgerung}
\newtheorem{Fakt}[factcnt]{Fakt}
\newenvironment{Beweis}{\begin{proof}[Beweis.]}{\end{proof}}
\newenvironment{Lemma}{\begin{lemma}}{\end{lemma}}
\newenvironment{Proof}{\begin{proof}}{\end{proof}}
\newenvironment{Theorem}{\begin{theorem}}{\end{theorem}}
\newenvironment{Problem}{\begin{problem}}{\end{problem}}
\newenvironment{Corollary}{\begin{corollary}}{\end{corollary}}
\newenvironment{Example}{\begin{example}}{\end{example}}
\newenvironment{Examples}{\begin{examples}}{\end{examples}}
\newenvironment{Definition}{\begin{definition}}{\end{definition}}
\makeatother
\begin{document}
\begin{frame}
\begin{theorem}[A theorem]\label{thm:1}
Some text.
\end{theorem}
\begin{definition}[A definition]\label{def:1}
Some text.
\end{definition}
Theorem \ref{thm:1} follows directly from Definition \ref{def:1}.
\end{frame}
\end{document}