在接受的答案中将当前定理类项目的名称/编号放在标题中,显示了如何在页面标题中放置(页面上的最后一个)定理、引理等的标签。例如,如果最后一个这样的项目是“定理 3.2”,那么它就会出现在页面标题中。
我正在使用\swapnumbers
与amsthm
包一起使用的,因此此类项目在页面正文中显示为“3.2 Theorem”。但相应的标题仍显示为“Theorem 3.2”。
是否也可以用类似定理的标签(“定理”等)来交换数字?
答案1
您必须注意,\swapnumbers
在定理定义之间可能会多次发出,这实际上是定理样式的一部分(实际上,它充当“样式修饰符”)。因此,处理该问题的正确方法是使用\thm@swap
(在其“内在”含义中!)在两个预定义的“标记样式”之间进行选择。
这是使用此策略提供与以下项完全兼容的新版本代码\swapnumbers
(編輯我希望能够纠正在在标题中包含类似定理的项目名称,并在可选参数中包含数学字母):
\documentclass[a4paper,twoside]{article}
\usepackage[T1]{fontenc} % Not necessary, but recommended.
\usepackage{etoolbox}
\usepackage{amsthm} % comment or uncomment as you prefer
\usepackage{amsfonts} % for "\mathbb"
\usepackage{fancyhdr}
\usepackage{lipsum}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE,LO]{\myBotmark} % "RE" just for testing purposes
\pagestyle{fancy}
\newtheorem{theorem}{Theorem}[section] % or "[chapter]", or whatever
\newtheorem{lemma} {Lemma} [section]
% A little trick to make this example work both with amsthm and without it;
% once you've made your choice, you do not need this code.
\makeatletter
\@ifdefinable\IfAmsThm{}
\@ifpackageloaded{amsthm}{
\let \IfAmsThm = \@firstoftwo
}{
\let \IfAmsThm = \@secondoftwo
}
\makeatother
\IfAmsThm{
\newtheorem*{spclaim}{Special Claim}
\swapnumbers
\theoremstyle{definition}
}{}
\newtheorem{defin}{Definition}[section]
%%%%%%%% BEGIN WIZARDRY %%%%%%%%
\makeatletter
\@ifdefinable\@my@claim@mark{\newmarks\@my@claim@mark}
\newcommand*\myMark[1]{% <<< MODIFIED
\begingroup
\let\label\relax \let\index\relax \let\glossary\relax
\let\protect\@unexpandable@protect
\marks\@my@claim@mark{#1}%
\endgroup
}
\newcommand*\myBotmark{\botmarks\@my@claim@mark}
\typeout{****************************************}
\@ifpackageloaded{amsthm}{\iftrue}{\iffalse}
\newcommand*\my@direct@mark[3]{%
\myMark{%
\thmname{#1}%
\thmnumber{\thmname{\ }#2}%
\thmnote{\ (#3)}%
}%
}
\newcommand*\my@swapped@mark[3]{%
\myMark{%
\thmnumber{#2}%
\thmname{\thmnumber{\ }#1}%
\thmnote{\ (#3)}%
}%
}
\patchcmd{\@begintheorem}{% search for:
\thm@swap\swappedhead\thmhead % more specific than before
}{% replace with:
\thm@swap\my@swapped@mark\my@direct@mark{#1}{#2}{#3}%
\thm@swap\swappedhead\thmhead
}{% execute if succeeded:
\typeout{>>> Made patch specific for amsthm.}
}{% execute if failed:
\typeout{>>> Patch specific for amsthm FAILED!}
}
\else
\apptocmd{\@begintheorem} {\myMark{#1\ #2}\ignorespaces}{}{}
\apptocmd{\@opargbegintheorem}{\myMark{%
#1\ #2%
\ (#3)% comment this line to leave Mickey Mouse out
\ignorespaces
}}{}{}
\typeout{>>> Made generic patch.}
\fi
\typeout{****************************************}
\makeatother
%%%%%%%% END WIZARDRY %%%%%%%%
\begin{document}
\section{First section}
\lipsum[1]
\begin{theorem}
This is the first theorem of the first section.
\end{theorem}
\lipsum[2]
\begin{theorem}
This is the second theorem of the first section.
\end{theorem}
\begin{theorem}[Donald Duck and~$\mathbb{Q}$]
The third theorem of the first section.
\end{theorem}
\IfAmsThm{
\begin{spclaim}
This is a special claim.
\end{spclaim}
}{}
% \begingroup
% \showboxbreadth = 1000
% \showboxdepth = 10
% \tracingonline = 1
% \showlists
% \endgroup
\lipsum[3-16]
\begin{theorem}
This is the fourth theorem of the first section.
\end{theorem}
\begin{defin}[Something new]
This is the first definition of the first section.
\end{defin}
\begin{defin}
This is the second definition of the first section.
\end{defin}
\lipsum[17]
\begin{lemma}
This is the first lemma of the first section.
\end{lemma}
\lipsum[18]
\begin{theorem}
This is the fifth theorem of the first section.
\end{theorem}
\lipsum[19-20]
\begin{lemma}[Uncle Scrooge and~$\mathbb{R}$]
The second lemma of the first section.
\end{lemma}
\lipsum[21-32]
\begin{theorem}
This is the sixth theorem of the first section.
\end{theorem}
\lipsum[33-36]
\begin{theorem}
This is the seventh theorem of the first section.
\end{theorem}
\begin{lemma}
This is the third lemma of the first section.
\end{lemma}
\begin{theorem}[Mickey Mouse and~$\mathbb{C}$]
The eighth theorem of the first section.
\end{theorem}
\lipsum[37-40]
\begin{theorem}
This is the ninth theorem of the first section.
\end{theorem}
\lipsum[41-48]
\begin{defin}
This is the third definition of the first section.
\end{defin}
\lipsum[49-64]
\begin{theorem}[The last one]
This is the tenth theorem of the first section.
\end{theorem}
\lipsum[65-80]
\begin{lemma}
This is the fourth lemma of the first section.
\end{lemma}
\begin{lemma}
This is the fifth lemma of the first section.
\end{lemma}
\begin{lemma}
This is the sixth lemma of the first section.
\end{lemma}
\begin{lemma}
This is the seventh lemma of the first section.
\end{lemma}
\begin{lemma}
This is the eighth lemma of the first section.
\end{lemma}
\begin{lemma}
This is the ninth lemma of the first section.
\end{lemma}
\begin{lemma}[Deep breath]
This is the tenth lemma of the first section.
\end{lemma}
\lipsum[81-84]
\begin{lemma}
This is the eleventh lemma of the first section.
\end{lemma}
\begin{lemma}
This is the twelfth lemma of the first section.
\end{lemma}
\begin{lemma}
This is the thirteenth lemma of the first section.
\end{lemma}
\begin{lemma}
This is the fourteenth lemma of the first section.
\end{lemma}
\begin{lemma}
This is the fifteenth lemma of the first section.
\end{lemma}
\begin{lemma}[Hexadecimal deep breath]
This is the sixteenth lemma of the first section.
\end{lemma}
% \lipsum[85-96]
\end{document}
再次强调,在这里显示输出是没有意义的:您必须自己尝试代码并检查其是否按预期运行。
答案2
在线条中
\apptocmd{\@begintheorem} {\myMark{#1\ #2}\ignorespaces}{}{}
\apptocmd{\@opargbegintheorem}{\myMark{%
#1\ #2%
\ (#3)% comment this line to leave "Mickey Mouse" out
\ignorespaces
}}{}{}
#1
與交换#2
。