我在 Beamer 中有两个示例,Example 1
和Example 2
。然后我希望Example 1 (ctd)
在 之后有Example 2
。以下不起作用:
\documentclass[notheorems]{beamer}
\usetheme{Pittsburgh}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\makeatletter
\ifbeamer@countsect
\newtheorem{theorem}{\translate{Theorem}}[section]
\else
\newtheorem{theorem}{\translate{Theorem}}
\fi
\theoremstyle{example}
\newtheorem{example}{\translate{Example}}
\setbeamertemplate{theorem begin}{%
\begin{center}
\begin{minipage}{0.9\textwidth}
\begin{\inserttheoremblockenv}
{%
\inserttheoremname
\inserttheoremnumber
\ifx\inserttheoremaddition\@empty\else\ (\inserttheoremaddition)\fi%
}%
}
\setbeamertemplate{theorem end}{%
\end{\inserttheoremblockenv}
\end{minipage}
\end{center}
}
\makeatother
\addtobeamertemplate{theorem begin}{%
\setbeamercolor{block title}{fg=green}%
\setbeamercolor{block body}{bg=gray}%
\setbeamerfont{block title}{size=\small,series=\bfseries}%
}{}
\newtheoremstyle{examplec}
{\topsep} {\topsep}%
{\upshape}% Body font
{}% Indent amount (empty = no indent, \parindent = para indent)
{\bfseries\scshape}% Thm head font
{.}% Punctuation after thm head
{1em}% Space after thm head (\newline = linebreak)
{\thmname{#1} \thmnumber{ #2}\thmnote{#3} (ctd)}% Thm head spec
\theoremstyle{examplec}
\newtheorem*{examplec}{\translate{Example}}
\begin{document}
\begin{frame}
\begin{example}
This is the first example.\label{myexample}
\end{example}
\begin{example}
This is the second example.
\end{example}
\begin{examplec}[\ref{myexample}]
Continuing first example.
\end{examplec}
\end{frame}
\end{document}
这将产生以下内容:
我想要的是:而不是Example (1)
,而是Example 1 (ctd)
。
我注意到解决方案继续 Beamer 中的计数器示例但是如果我将我的配置保留在序言中,它似乎不起作用(这就是 MWE 有点长的原因)——我想保留(ctd)部分。
非常感谢您的帮助。谢谢!
答案1
与其摆弄新定理的外观,不如定义一个调整计数器并使用现有定理的新环境,这样也许更容易example
。
\documentclass[notheorems]{beamer}
\usetheme{Pittsburgh}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\makeatletter
\ifbeamer@countsect
\newtheorem{theorem}{\translate{Theorem}}[section]
\else
\newtheorem{theorem}{\translate{Theorem}}
\fi
\theoremstyle{example}
\newtheorem{example}{\translate{Example}}
\setbeamertemplate{theorem begin}{%
\begin{center}
\begin{minipage}{0.9\textwidth}
\begin{\inserttheoremblockenv}
{%
\inserttheoremname
\inserttheoremnumber
\ifx\inserttheoremaddition\@empty\else\ (\inserttheoremaddition)\fi%
}%
}
\setbeamertemplate{theorem end}{%
\end{\inserttheoremblockenv}
\end{minipage}
\end{center}
}
\makeatother
\addtobeamertemplate{theorem begin}{%
\setbeamercolor{block title}{fg=green}%
\setbeamercolor{block body}{bg=gray}%
\setbeamerfont{block title}{size=\small,series=\bfseries}%
}{}
\usepackage{refcount}
\setrefcountdefault{1}
\newcounter{saveexample}
\newenvironment{examplec}[1][]{%
\setcounter{saveexample}{\value{example}}%
\setcounterref{example}{#1}%
\addtocounter{example}{-1}%
\begin{example}[cont.]}{\end{example}%
\setcounter{example}{\thesaveexample}%
}
\begin{document}
\begin{frame}
\begin{example}
This is the first example.\label{myexample}
\end{example}
\begin{example}
This is the second example.
\end{example}
\begin{example}
This is the second example.
\end{example}
\begin{examplec}[myexample]
Continuing first example.
\end{examplec}
\begin{example}
This is the second example.
\end{example}
\end{frame}
\end{document}
答案2
由于“调整计数器”很危险,我不建议这样做。(“调整计数器”可能会导致以微妙的方式破坏超链接功能,这与不再确保锚点名称的唯一性有关。)
意识到
你的
examplec
-theorem-environment 没有编号。\inserttheoremname
表示环境的名称;
\inserttheoremaddition
表示环境的可选参数;
\inserttheoremnumber
对于编号的定理环境,表示所讨论定理的编号,对于未编号的定理,始终为空。
让我们看看你的theorem begin
模板中的以下几行:
\inserttheoremname
\inserttheoremnumber
\ifx\inserttheoremaddition\@empty\else\ (\inserttheoremaddition)\fi%
- 对于未编号的
examplec
定理环境,\inserttheoremnumber
它始终是空的。 - 使用未编号的
examplec
-theorem-environment,\inserttheoremaddition
表示环境的可选参数,它是\ref
用于引用要继续的环境的标签的-command,不带-phrase(ctd)
。
因此这些行应该是这样的:
\inserttheoremname~%
\ifx\inserttheoremnumber\@empty
\inserttheoremaddition~(ctd)%
\else
\inserttheoremnumber~\inserttheoremaddition
\fi
使用此方法的警告:
如果您将\ref{myexample}
其作为可选参数提供给examplec
-environment,\inserttheoremaddition
则将扩展为该标记序列。
\ref
该标记序列内的将产生一个超链接,并且您的标题examplec
将具有模式
Example ⟨hyperlink; target:=Example 1; text-phrase:=1⟩(ctd)
我认为,这种模式 更可取。
⟨hyperlink; target:=Example 1; text-phrase:=Example 1 (ctd)⟩
因此在下面的例子中我插入了一堆可扩展的代码来检查可选参数是否是模式\ref{<name of label>}
。
如果是,<name of label>
则提取并根据优选模式创建超链接。
\ref
这种模式检查也确实满足了您在后续主题问题中提出的通过 -command 标记引用的要求使用 \ref{name} 而不是直接命名来引用。
另一个问题是:
如果继续的不是示例而是其延续,您希望什么行为?(延续的延续......)
\ref
当前,每个延续都采用通过-command 在可选参数中提供的数字并将\@currentlabel
其自己的放置\phantomtarget
。
因此,每个延续都会获得延续事物的编号,并且其标题将链接到\phantomtarget
延续事物所放置的位置。
\documentclass[notheorems]{beamer}
\usepackage{refcount}%
\usetheme{Pittsburgh}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\makeatletter
%%=============================================================================
%% \UD@firstoftwo, \UD@secondoftwo, \UD@Exchange, \UD@gobbletwo
%%=============================================================================
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@Exchange[2]{#2#1}%
\newcommand\UD@gobbletwo[2]{}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is empty>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
%%
\newcommand\UD@CheckWhetherNull[1]{%
\romannumeral0\expandafter\UD@secondoftwo\string{\expandafter
\UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
\UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\expandafter\UD@firstoftwo{ }{}%
\UD@secondoftwo}{\expandafter\expandafter\UD@firstoftwo{ }{}\UD@firstoftwo}%
}%
%%-----------------------------------------------------------------------------
%% Check whether brace-balanced argument starts with the
%% control word token \ref
%%.............................................................................
%% \UD@CheckWhetherLeadingRef{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case <argument
%% which is to be checked>'s 1st token is
%% the control word token \ref >}%
%% {<Tokens to be delivered in case <argument
%% which is to be checked>'s 1st token is not
%% the control word token \ref >}%
\newcommand\UD@CheckWhetherLeadingRef[1]{%
\romannumeral0\UD@CheckWhetherNull{#1}%
{\expandafter\expandafter\UD@firstoftwo{ }{}\UD@secondoftwo}%
{\expandafter\UD@secondoftwo\string{\UD@CheckWhetherLeadingRefB.#1\ref}{}}%
}%
\newcommand\UD@CheckWhetherLeadingRefB{}%
\long\def\UD@CheckWhetherLeadingRefB#1\ref{%
\expandafter\UD@CheckWhetherNull\expandafter{\UD@secondoftwo#1{}}%
{\UD@Exchange{\UD@firstoftwo}}{\UD@Exchange{\UD@secondoftwo}}%
{\UD@Exchange{ }{\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter}\expandafter\expandafter
\expandafter}\expandafter\UD@secondoftwo\expandafter{\string}%
}%
%%-----------------------------------------------------------------------------
%% Check whether argument's first token is a catcode-1-character
%%.............................................................................
%% \UD@CheckWhetherBrace{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked has leading
%% catcode-1-token>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked has no leading
%% catcode-1-token>}%
\newcommand\UD@CheckWhetherBrace[1]{%
\romannumeral0\expandafter\UD@secondoftwo\expandafter{\expandafter{%
\string#1.}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\expandafter\UD@firstoftwo{ }{}%
\UD@firstoftwo}{\expandafter\expandafter\UD@firstoftwo{ }{}\UD@secondoftwo}%
}%
%%-----------------------------------------------------------------------------
%% Check whether brace-balanced argument is of pattern \ref{}
%%-----------------------------------------------------------------------------
\newcommand\UD@CheckWhetherrefpattern[1]{%
\romannumeral0%
\UD@CheckWhetherLeadingRef{#1}{%
\expandafter\UD@CheckWhetherBrace\expandafter{\UD@gobbletwo{}#1}{%
\expandafter\UD@CheckWhetherNull\expandafter{\UD@gobbletwo#1}{%
\expandafter\expandafter\UD@firstoftwo{ }{}\UD@firstoftwo
}{%
\expandafter\expandafter\UD@firstoftwo{ }{}\UD@secondoftwo
}%
}{%
\expandafter\expandafter\UD@firstoftwo{ }{}\UD@secondoftwo
}%
}{%
\expandafter\expandafter\UD@firstoftwo{ }{}\UD@secondoftwo
}%
}%
%%=============================================================================
\newcounter{phantomtarget}%
\renewcommand*{\thephantomtarget}{phantom.\the\value{phantomtarget}}%
\newcommand*{\phantomtarget}{%
\stepcounter{phantomtarget}%
\hypertarget{\thephantomtarget}{}%
\edef\@currentHref{\thephantomtarget}%
}%
%%=============================================================================
\ifbeamer@countsect
\newtheorem{theorem}{\translate{Theorem}}[section]%
\else
\newtheorem{theorem}{\translate{Theorem}}%
\fi
\theoremstyle{example}
\newtheorem{example}{\translate{Example}}
\setbeamertemplate{theorem begin}{%
\begin{center}%
\begin{minipage}{0.9\textwidth}%
\expandafter\UD@CheckWhetherNull\expandafter{\inserttheoremnumber}{%
\expandafter\UD@CheckWhetherrefpattern\expandafter{\inserttheoremaddition}{%
\edef\@currentlabel{%
\getrefbykeydefault{\expandafter\UD@secondoftwo\inserttheoremaddition}%
{}%
{??}%
}%
\refused{\expandafter\UD@secondoftwo\inserttheoremaddition}%
\phantomtarget%\phantomsection
}{}%
}{}%
\begin{\inserttheoremblockenv}{%
% Your examplec-theorem is not numbered, thus \inserttheoremnumber
% will be empty
\expandafter\UD@CheckWhetherNull\expandafter{\inserttheoremnumber}{%
\expandafter\UD@CheckWhetherrefpattern\expandafter{\inserttheoremaddition}{%
\hyperref[{\expandafter\UD@secondoftwo\inserttheoremaddition}]{%
\inserttheoremname~\ref*{\expandafter\UD@secondoftwo\inserttheoremaddition}~(ctd)%
}%
}{%
\inserttheoremname~\inserttheoremaddition~(ctd)%
}%
}{%
\inserttheoremname~\inserttheoremnumber~\inserttheoremaddition
}%
}%
}%
\setbeamertemplate{theorem end}{%
\end{\inserttheoremblockenv}%
\end{minipage}%
\end{center}%
}%
\makeatother
\addtobeamertemplate{theorem begin}{%
%% Do this in case you wish examples to be of equal color as examples:
%\setbeamercolor{block title}{parent=example text}%
%% Do this in case you wish examples to be of some light green:
\setbeamercolor{block title}{fg=green}%
%%
\setbeamercolor{block body}{bg=gray}%
\setbeamerfont{block title}{size=\small,series=\bfseries}%
}{}
\newtheoremstyle{examplec}
{\topsep} {\topsep}%
{\upshape}% Body font
{}% Indent amount (empty = no indent, \parindent = para indent)
{\bfseries\scshape}% Thm head font
{.}% Punctuation after thm head
{1em}% Space after thm head (\newline = linebreak)
{\thmname{#1} \thmnumber{#2}\thmnote{#3} (ctd)}% Thm head spec
\theoremstyle{examplec}
\newtheorem*{examplec}{\translate{Example}}
\begin{document}
\begin{frame}
\begin{example}
This is the first example.\label{example1}
\end{example}
\begin{example}
This is the second example.\label{example2}
\end{example}
\end{frame}
\begin{frame}
\begin{examplec}[\ref{example1}]
Continuing first example.\label{example1c}
\end{examplec}
\end{frame}
\begin{frame}
\begin{examplec}[\ref{example1c}]
Continuing first example.\label{example1c1}
\end{examplec}
\end{frame}
\end{document}
第 1 页:
第2页:
第 3 页: