继续测试章节是否有节:为了以良好的方式对定理类环境进行编号,建议在文档逻辑部分的开头知道该逻辑部分是否包含更深的逻辑部分。换句话说,您希望在章节(或节或小节)的开头知道X某一节(分别为小节或小小节)是否出现在X结束了。这将让你正确地选择定理的编号级别。
例如,让我们考虑一下本节中的定理s一章C。有两种情况。
如果C。s逻辑上不包含任何小节,你可以在其中对定理进行编号C。s作为C。s.1,C。s.2,...,因为这些数字不会与任何截面元素的数字混淆。
如果C。s逻辑上至少包含一个小节,建议你将第一个小节之前的定理编号为C。s.0.1,C。s.0.2,......并将各小节中的定理编号为C。s.1.⁅无论如何⁆,C。s.2.⁅无论如何,....通过写作C。s。党卫军.⁅不管怎样⁆,我们的意思是党卫军是小节编号,你递归地应用同样的规则:检查是否C。s。党卫军是否有子节,并列举其中的定理C。s。党卫军因此
- C。s。党卫军。社保局.1,C。s。党卫军。社保局.2,…(其中社保局是子节编号)
- 或C。s。党卫军.1,C。s。党卫军.2,….
有一种非常糟糕的手动方法可以实现这一点(我采取了需要解决方案的序言):
\documentclass[envcountsame,envcountsect]{svmono}%%% from http://www.springer.com/gp/authors-editors/book-authors-editors/resources-guidelines/book-manuscript-guidelines/manuscript-preparation/5636
\usepackage{mathtools}%%% loads amsmath internally
\PassOptionsToPackage{mainaux,starttoc,index,glossary}{rerunfilecheck}
\usepackage[unicode,hidelinks]{hyperref}
\usepackage[compress]{cleveref}
\crefname{theorem}{Thm.}{Thms.}%%% Abbreviate in the middle of a sentence.
\Crefname{theorem}{Theorem}{Theorems}%%% No abbreviation should start any sentence.
\crefrangeformat{theorem}{Thms.\@ #3#1#4 -- #5#2#6}%%% Allow for line breaks everywhere.
\Crefrangeformat{theorem}{Theorems #3#1#4 -- #5#2#6}%%% Allow for line breaks everywhere; no abbreviation should start any sentence.
\begin{document}
\numberwithin{theorem}{chapter}
\chapter{Introduction}
\begin{theorem}\label{thm:A}This theorem should have number 1.1 .\end{theorem}
\begin{theorem}\label{thm:B}This theorem should have number 1.2 .\end{theorem}
\part{First Part}
No theorems here.
\chapter{Second Chapter}
\begin{theorem}\label{thm:C}This theorem should have number 2.1 .\end{theorem}
\begin{theorem}\label{thm:D}This theorem should have number 2.2 .\end{theorem}
\numberwithin{theorem}{section}
\part{Second Part}
No theorems here.
\chapter{Third Chapter}
\begin{theorem}\label{thm:E}This theorem should have number 3.0.1 .\end{theorem}
\begin{theorem}\label{thm:F}This theorem should have number 3.0.2 .\end{theorem}
\section{Some Section}
\begin{theorem}\label{thm:G}This theorem should have number 3.1.1 .\end{theorem}
\begin{theorem}\label{thm:H}This theorem should have number 3.1.2 .\end{theorem}
\part{Third Part}
No theorems here.
\chapter{Fourth Chapter}
\begin{theorem}\label{thm:I}This theorem should have number 4.0.1 .\end{theorem}
\begin{theorem}\label{thm:J}This theorem should have number 4.0.2 .\end{theorem}
\numberwithin{theorem}{subsection}
\section{Some Section}
\begin{theorem}\label{thm:K}This theorem should have number 4.1.0.1 .\end{theorem}
\begin{theorem}\label{thm:L}This theorem should have number 4.1.0.2 .\end{theorem}
\subsection{Some Subsection}
\begin{theorem}\label{thm:M}This theorem should have number 4.1.1.1 .\end{theorem}
\begin{theorem}\label{thm:N}This theorem should have number 4.1.1.2 .\end{theorem}
\numberwithin{theorem}{section}
\part{Fourth Part}
No theorems here.
\chapter{Fifth Chapter}
\begin{theorem}\label{thm:O}This theorem should have number 5.0.1 .\end{theorem}
\begin{theorem}\label{thm:P}This theorem should have number 5.0.2 .\end{theorem}
\numberwithin{theorem}{subsection}
\section{Some Section}
\begin{theorem}\label{thm:Q}This theorem should have number 5.1.0.1 .\end{theorem}
\begin{theorem}\label{thm:R}This theorem should have number 5.1.0.2 .\end{theorem}
\numberwithin{theorem}{subsubsection}
\subsection{Some Subsection}
\begin{theorem}\label{thm:S}This theorem should have number 5.1.1.0.1 .\end{theorem}
\begin{theorem}\label{thm:T}This theorem should have number 5.1.1.0.2 .\end{theorem}
\subsubsection{Some Subsubsection}
\begin{theorem}\label{thm:U}This theorem should have number 5.1.1.1.1 .\end{theorem}
\begin{theorem}\label{thm:V}This theorem should have number 5.1.1.1.2 .\end{theorem}
Now, let's reference all of them: \cref{thm:A,thm:B,thm:C,thm:D,thm:E,thm:F,thm:G,thm:H,thm:I,thm:J,thm:K,thm:L,thm:M,thm:N,thm:O,thm:P,thm:Q,thm:R,thm:S,thm:T,thm:U,thm:V}.
However, I expect ``Thms.\@ 1.1 -- 5.1.1.1.2'' here.
\end{document}
你得到你想要的:
第一部分之前:
在第一部分中:
在第二部分中:
在第三部分中:
第四部分:
但是,这种方法容易出错:每当您添加、删除或更改任何分段命令(\subsubsection
、\subsection
、\section
、\chapter
或许还有\part
)时,您都需要检查并调整您的\numberwithin
s。
在一个更好的世界中,您甚至不需要添加\numberwithin
s,而是将所有复杂性都转移到序言中的分段命令(以及可能的类定理环境)的定义中。分段命令可能会将有关自身的信息写入某个辅助文件,并在下次运行 时再次从中读取{pdf|xe|lua}latex
。
怎么做到呢?即,如何调整您的分段命令(以及可能的类定理环境),使它们自动检查是否存在比当前分段元素更深的未来分段元素,并\numberwithin
自动发出相应的 s ?(为了降低此任务的复杂性,请首先不要考虑附录和所有后记,这些通常存在于书中。)如果它使任务更容易,您甚至可以考虑创建分段环境,例如,,\begin{myPart}{title}[short title]…\end{myPart}
...,\begin{mySubsubsection}{title}[short title]…\end{mySubSubsection}
而不是传统的\part{title}[short title]
,...,\subsubsection{Title}[short title]
。
顺便问一下,要怎么做才能将cleveref
定理列表压缩到一个范围内?该选项compress
存在,但没有明显的效果。
编辑:约翰的解决方案http://tex.stackexchange.com/a/564190(截至 2020 年 12 月 9 日星期三 04:19:55 UTC)对边距内容的位置有如下影响。考虑原始文件,例如,mwe1.tex
包含
\documentclass[envcountsame,envcountsect]{svmono}%%% taken from https://www.springer.com/gp/authors-editors/book-authors-editors/your-publication-journey/manuscript-preparation
\usepackage{mathtools}%%% loads amsmath internally
\usepackage{marginfix}%%% we do need it in a non-mwe
\usepackage{todonotes}
\usepackage{lipsum}
\begin{document}
\chapter{First chapter}
\lipsum[1]
\marginpar{Margin text}
\chapter{Second chapter}
Main text.\todo{Todo note}%
\end{document}
及其改编mwe2.tex
,包含
\documentclass[envcountsame,envcountsect]{svmono}%%% taken from https://www.springer.com/gp/authors-editors/book-authors-editors/your-publication-journey/manuscript-preparation
\usepackage{mathtools}%%% loads amsmath internally
\usepackage{marginfix}%%% we do need it in a non-mwe
\usepackage{todonotes}
\usepackage{lipsum}
%%% Making the enumeration style of the theorem-like environments autmomatically follow the numbering of ((sub-)sub-)sections and chapters in a logical way; cf. http://tex.stackexchange.com/a/564190 :
\newcommand{\newchapter}[2]{\expandafter\gdef\csname chapter#1\endcsname{#2}}% see aux file
\newcommand{\newsection}[2]{\expandafter\gdef\csname section#1\endcsname{#2}}
\newcommand{\newsubsection}[2]{\expandafter\gdef\csname subsection#1\endcsname{#2}}
\makeatletter
\newenvironment{Chapter}{\stepcounter{chapter}%
\@ifundefined{chapter\thechapter}{\numberwithin{theorem}{chapter}}%
{\numberwithin{theorem}{\csname chapter\thechapter\endcsname}}%
\addtocounter{chapter}{-1}%
\chapter}{\par\ifnum\c@section>0%
\immediate\write\@auxout{\string\newchapter{\thechapter}{section}}%
\fi}
\newenvironment{Section}{\stepcounter{section}%
\@ifundefined{section\thesection}{\numberwithin{theorem}{section}}%
{\numberwithin{theorem}{\csname section\thesection\endcsname}}%
\addtocounter{section}{-1}%
\section}{\par\ifnum\c@subsection>0%
\immediate\write\@auxout{\string\newsection{\thesection}{subsection}}%
\fi}
\newenvironment{Subsection}{\stepcounter{subsection}%
\@ifundefined{subsection\thesubsection}{\numberwithin{theorem}{subsection}}%
{\numberwithin{theorem}{\csname subsection\thesubsection\endcsname}}%
\addtocounter{subsection}{-1}%
\subsection}{\par\ifnum\c@subsubsection>0%
\immediate\write\@auxout{\string\newsubsection{\thesubsection}{subsubsection}}%
\fi}
\makeatother
\begin{document}
\begin{Chapter}{First chapter}
\lipsum[1]
\marginpar{Margin text}
\end{Chapter}%
\begin{Chapter}{Second chapter}
Main text.\todo{Todo note}%
\end{Chapter}%
\end{document}
pdflatex
循环运行这两个文件直到稳定下来,根据会产生以下差异diffpdf
(左边是 的有趣输出部分mwe1.tex
,右边是 的有趣输出部分mwe2.tex
):
如您所见,应用该解决方案使待办事项注释的位置下降。虽然在最小工作示例中这似乎是一个小麻烦,但在一本大书中,这种变化会给页边距中的待办事项注释带来问题:它们在逻辑上看起来太低了,即使它们不在章节或部分的开头或结尾附近。无论如何,从排字员的角度来看,解决分段问题的方法必须(大部分)与待办事项注释的位置无关。
答案1
这显示了如何使用 aux 文件。要删除所有\postchapter
、\postsection
和\postsubsection
条目,请将它们添加到每个可以启动新命令的命令中,包括\AtEndDocument
。
摆脱\startchapter
etc 命令比较棘手,因为\thechapter
它直到代码深处的某个地方才有效,而且由于\chapter
etc. 传递参数的方式,你不能将它添加到末尾。
\documentclass[envcountsame,envcountsect]{svmono}%%% from
http://www.springer.com/gp/authors-editors/book-authors-editors/resources-guidelines/book-manuscript-guidelines/manuscript-preparation/5636
\usepackage{mathtools}%%% loads amsmath internally
\PassOptionsToPackage{mainaux,starttoc,index,glossary}{rerunfilecheck}
\usepackage[unicode,hidelinks]{hyperref}
\usepackage[compress]{cleveref}
\crefname{theorem}{Thm.}{Thms.}%%% Abbreviate in the middle of a sentence.
\Crefname{theorem}{Theorem}{Theorems}%%% No abbreviation should start any sentence.
\crefrangeformat{theorem}{Thms.\@ #3#1#4 -- #5#2#6}%%% Allow for line breaks everywhere.
\Crefrangeformat{theorem}{Theorems #3#1#4 -- #5#2#6}%%% Allow for line breaks everywhere; no abbreviation should start any sentence.
\makeatletter
\newcommand{\postchapter}{\ifnum\c@section>0
\immediate\write\@auxout{\string\newchapter{\thechapter}{section}}
\fi}
\newcommand{\newchapter}[2]{\expandafter\gdef\csname chapter#1\endcsname{#2}}% at \begin{document}
\newcommand\startchapter{\@ifundefined{chapter\thechapter}{\numberwithin{theorem}{chapter}}%
{\numberwithin{theorem}{\csname chapter\thechapter\endcsname}}\ignorespaces}
\newcommand{\postsection}{\ifnum\c@subsection>0
\immediate\write\@auxout{\string\newsection{\thesection}{subsection}}
\fi}
\newcommand{\newsection}[2]{\expandafter\gdef\csname section#1\endcsname{#2}}% at \begin{document}
\newcommand\startsection{\@ifundefined{section\thesection}{}%
{\numberwithin{theorem}{\csname section\thesection\endcsname}}\ignorespaces}
\newcommand{\postsubsection}{\ifnum\c@subsubsection>0
\immediate\write\@auxout{\string\newsubsection{\thesubsection}{subsubsection}}
\fi}
\newcommand{\newsubsection}[2]{\expandafter\gdef\csname subsection#1\endcsname{#2}}% at \begin{document}
\newcommand\startsubsection{\@ifundefined{subsection\thesubsection}{}%
{\numberwithin{theorem}{\csname subsection\thesubsection\endcsname}}\ignorespaces}
\makeatother
\begin{document}
\csname subsection5.1.1\csname
\chapter{Introduction}
\startchapter
\begin{theorem}\label{thm:A}This theorem should have number 1.1 .\end{theorem}
\begin{theorem}\label{thm:B}This theorem should have number 1.2 .\end{theorem}
\postchapter
\part{First Part}
No theorems here.
\chapter{Second Chapter}
\startchapter
\begin{theorem}\label{thm:C}This theorem should have number 2.1 .\end{theorem}
\begin{theorem}\label{thm:D}This theorem should have number 2.2 .\end{theorem}
\postchapter
\part{Second Part}
No theorems here.
\chapter{Third Chapter}
\startchapter
\begin{theorem}\label{thm:E}This theorem should have number 3.0.1 .\end{theorem}
\begin{theorem}\label{thm:F}This theorem should have number 3.0.2 .\end{theorem}
\section{Some Section}
\startsection
\begin{theorem}\label{thm:G}This theorem should have number 3.1.1 .\end{theorem}
\begin{theorem}\label{thm:H}This theorem should have number 3.1.2 .\end{theorem}
\postsection
\postchapter
\part{Third Part}
No theorems here.
\chapter{Fourth Chapter}
\startchapter
\begin{theorem}\label{thm:I}This theorem should have number 4.0.1 .\end{theorem}
\begin{theorem}\label{thm:J}This theorem should have number 4.0.2 .\end{theorem}
\section{Some Section}
\startsection
\begin{theorem}\label{thm:K}This theorem should have number 4.1.0.1 .\end{theorem}
\begin{theorem}\label{thm:L}This theorem should have number 4.1.0.2 .\end{theorem}
\subsection{Some Subsection}
\startsubsection
\begin{theorem}\label{thm:M}This theorem should have number 4.1.1.1 .\end{theorem}
\begin{theorem}\label{thm:N}This theorem should have number 4.1.1.2 .\end{theorem}
\postsubsection
\postsection
\postchapter
\part{Fourth Part}
No theorems here.
\chapter{Fifth Chapter}
\startchapter
\begin{theorem}\label{thm:O}This theorem should have number 5.0.1 .\end{theorem}
\begin{theorem}\label{thm:P}This theorem should have number 5.0.2 .\end{theorem}
\section{Some Section}
\startsection
\begin{theorem}\label{thm:Q}This theorem should have number 5.1.0.1 .\end{theorem}
\begin{theorem}\label{thm:R}This theorem should have number 5.1.0.2 .\end{theorem}
\subsection{Some Subsection}
\startsubsection
\begin{theorem}\label{thm:S}This theorem should have number 5.1.1.0.1 .\end{theorem}
\begin{theorem}\label{thm:T}This theorem should have number 5.1.1.0.2 .\end{theorem}
\subsubsection{Some Subsubsection}
\begin{theorem}\label{thm:U}This theorem should have number 5.1.1.1.1 .\end{theorem}
\begin{theorem}\label{thm:V}This theorem should have number 5.1.1.1.2 .\end{theorem}
\postsubsection
\postsection
\postchapter
Now, let's reference all of them: \cref{thm:A,thm:B,thm:C,thm:D,thm:E,thm:F,thm:G,thm:H,thm:I,thm:J,thm:K,thm:L,thm:M,thm:N,thm:O,thm:P,thm:Q,thm:R,thm:S,thm:T,thm:U,thm:V}.
However, I expect ``Thms.\@ 1.1 -- 5.1.1.1.2'' here.
\end{document}
此版本是使用环境实现的。
\documentclass[envcountsame,envcountsect]{svmono}%%% from http://www.springer.com/gp/authors-editors/book-authors-editors/resources-guidelines/book-manuscript-guidelines/manuscript-preparation/5636
\usepackage{mathtools}%%% loads amsmath internally
\PassOptionsToPackage{mainaux,starttoc,index,glossary}{rerunfilecheck}
\usepackage[unicode,hidelinks]{hyperref}
\usepackage[compress]{cleveref}
\crefname{theorem}{Thm.}{Thms.}%%% Abbreviate in the middle of a sentence.
\Crefname{theorem}{Theorem}{Theorems}%%% No abbreviation should start any sentence.
\crefrangeformat{theorem}{Thms.\@ #3#1#4 -- #5#2#6}%%% Allow for line breaks everywhere.
\Crefrangeformat{theorem}{Theorems #3#1#4 -- #5#2#6}%%% Allow for line breaks everywhere; no abbreviation should start any sentence.
\newcommand{\newchapter}[2]{\expandafter\gdef\csname chapter#1\endcsname{#2}}% see aux file
\newcommand{\newsection}[2]{\expandafter\gdef\csname section#1\endcsname{#2}}
\newcommand{\newsubsection}[2]{\expandafter\gdef\csname subsection#1\endcsname{#2}}
\makeatletter
\newenvironment{Chapter}{\stepcounter{chapter}%
\@ifundefined{chapter\thechapter}{\numberwithin{theorem}{chapter}}%
{\numberwithin{theorem}{\csname chapter\thechapter\endcsname}}%
\addtocounter{chapter}{-1}%
\chapter}{\par\ifnum\c@section>0
\immediate\write\@auxout{\string\newchapter{\thechapter}{section}}
\fi}
\newenvironment{Section}{\stepcounter{section}%
\@ifundefined{section\thesection}{\numberwithin{theorem}{section}}%
{\numberwithin{theorem}{\csname section\thesection\endcsname}}%
\addtocounter{section}{-1}%
\section}{\par\ifnum\c@subsection>0
\immediate\write\@auxout{\string\newsection{\thesection}{subsection}}
\fi}
\newenvironment{Subsection}{\stepcounter{subsection}%
\@ifundefined{subsection\thesubsection}{\numberwithin{theorem}{subsection}}%
{\numberwithin{theorem}{\csname subsection\thesubsection\endcsname}}%
\addtocounter{subsection}{-1}%
\subsection}{\par\ifnum\c@subsubsection>0
\immediate\write\@auxout{\string\newsubsection{\thesubsection}{subsubsection}}
\fi}
\makeatother
\begin{document}
\begin{Chapter}[short title]{Introduction}
\begin{theorem}\label{thm:A}This theorem should have number 1.1 .\end{theorem}
\begin{theorem}\label{thm:B}This theorem should have number 1.2 .\end{theorem}
\end{Chapter}
\part{First Part}
No theorems here.
\begin{Chapter}{Second Chapter}
\begin{theorem}\label{thm:C}This theorem should have number 2.1 .\end{theorem}
\begin{theorem}\label{thm:D}This theorem should have number 2.2 .\end{theorem}
\end{Chapter}
\part{Second Part}
No theorems here.
\begin{Chapter}{Third Chapter}
\begin{theorem}\label{thm:E}This theorem should have number 3.0.1 .\end{theorem}
\begin{theorem}\label{thm:F}This theorem should have number 3.0.2 .\end{theorem}
\begin{Section}{Some Section}
\begin{theorem}\label{thm:G}This theorem should have number 3.1.1 .\end{theorem}
\begin{theorem}\label{thm:H}This theorem should have number 3.1.2 .\end{theorem}
\end{Section}
\end{Chapter}
\part{Third Part}
No theorems here.
\begin{Chapter}{Fourth Chapter}
\begin{theorem}\label{thm:I}This theorem should have number 4.0.1 .\end{theorem}
\begin{theorem}\label{thm:J}This theorem should have number 4.0.2 .\end{theorem}
\begin{Section}{Some Section}
\begin{theorem}\label{thm:K}This theorem should have number 4.1.0.1 .\end{theorem}
\begin{theorem}\label{thm:L}This theorem should have number 4.1.0.2 .\end{theorem}
\begin{Subsection}{Some Subsection}
\begin{theorem}\label{thm:M}This theorem should have number 4.1.1.1 .\end{theorem}
\begin{theorem}\label{thm:N}This theorem should have number 4.1.1.2 .\end{theorem}
\end{Subsection}
\end{Section}
\end{Chapter}
\part{Fourth Part}
No theorems here.
\begin{Chapter}{Fifth Chapter}
\begin{theorem}\label{thm:O}This theorem should have number 5.0.1 .\end{theorem}
\begin{theorem}\label{thm:P}This theorem should have number 5.0.2 .\end{theorem}
\begin{Section}{Some Section}
\begin{theorem}\label{thm:Q}This theorem should have number 5.1.0.1 .\end{theorem}
\begin{theorem}\label{thm:R}This theorem should have number 5.1.0.2 .\end{theorem}
\begin{Subsection}{Some Subsection}
\begin{theorem}\label{thm:S}This theorem should have number 5.1.1.0.1 .\end{theorem}
\begin{theorem}\label{thm:T}This theorem should have number 5.1.1.0.2 .\end{theorem}
\subsubsection{Some Subsubsection}
\begin{theorem}\label{thm:U}This theorem should have number 5.1.1.1.1 .\end{theorem}
\begin{theorem}\label{thm:V}This theorem should have number 5.1.1.1.2 .\end{theorem}
\end{Subsection}
\end{Section}
\end{Chapter}
Now, let's reference all of them: \cref{thm:A,thm:B,thm:C,thm:D,thm:E,thm:F,thm:G,thm:H,thm:I,thm:J,thm:K,thm:L,thm:M,thm:N,thm:O,thm:P,thm:Q,thm:R,thm:S,thm:T,thm:U,thm:V}.
However, I expect ``Thms.\@ 1.1 -- 5.1.1.1.2'' here.
\end{document}