以下是我想要实现的目标:
第 1 章
。...
定理 1.1。...
第
1.1 节
。...
定理 1.1.1。...
第
1.1.1 小节。...
定理
1.1.1.1。
这有可能吗?如果可能的话,怎么做?...
答案1
使用etoolbox
包裹您可以修补分段命令(\chapter
、\section
、\subsection
、 ...)以重新定义计数器的工作方式theorem
。theorem
通过以下方式在每个分段单元重置计数器\@addtoreset
,尽管也可以使用chngcntr
包裹)下面是一个可以工作的最小示例,它正是这样做的:
\documentclass{book}
\usepackage{etoolbox}% http://ctann.org/pkg/etoolbox
\newtheorem{theorem}{Theorem}
% Modify theorem counter to match that of the section unit
\preto{\chapter}{\renewcommand{\thetheorem}{\thechapter.\arabic{theorem}}}%
\preto{\section}{\renewcommand{\thetheorem}{\thesection.\arabic{theorem}}}%
\preto{\subsection}{\renewcommand{\thetheorem}{\thesubsection.\arabic{theorem}}}%
% Reset the counter at every sectional unit
\makeatletter
\@addtoreset{theorem}{chapter}
\@addtoreset{theorem}{section}
\@addtoreset{theorem}{subsection}
\makeatother
\begin{document}
\chapter{First chapter}
\begin{theorem} This is a theorem \end{theorem}
\section{First section}
\begin{theorem} This is a theorem \end{theorem}
\subsection{First subsection}
\begin{theorem} This is a theorem \end{theorem}
\section{Second section}
\begin{theorem} This is a theorem \end{theorem}
\subsection{First subsection}
\begin{theorem} This is a theorem \end{theorem}
\begin{theorem} This is a theorem \end{theorem}
\subsection{Second subsection}
\begin{theorem} This is a theorem \end{theorem}
\end{document}
答案2
也许这可以帮助你……
\documentclass{scrbook}
\usepackage{etoolbox}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\makeatletter
% save current section numbering
\AtBeginEnvironment{theorem}{\edef\tmpsect{\@currentlabel}}
% reset theorem counter with all headings
\@addtoreset{theorem}{chapter}
\@addtoreset{theorem}{section}
\@addtoreset{theorem}{subsection}
% add current section numbering to theorem number
\renewcommand{\thetheorem}{\tmpsect-\arabic{theorem}}
\makeatother
\begin{document}
\chapter{Chapter}
\begin{theorem}
Text
\end{theorem}
\section{Section}
\begin{theorem}
Text
\end{theorem}
\section{Section}
\begin{theorem}
Text
\end{theorem}
\subsection{Subsection}
\begin{theorem}
Text
\end{theorem}
\section{Section}
\begin{theorem}
Text
\end{theorem}
\subsection{Subsection}
\begin{theorem}
Text
\end{theorem}
\section{Section}
\begin{theorem}
Text
\end{theorem}
\subsubsection{Subsubsection}
\begin{theorem}
Text
\end{theorem}
\section{Section}
\begin{theorem}
Text
\end{theorem}
\subsection{Subsection}
\begin{theorem}
Text
\end{theorem}
\end{document}
如果没有,请尝试提供一个最小的工作示例并澄清您的问题。
笔记
表示\@currentlabel
当前标签(哇...),可以是另一个标签,也可以是当前部分。但正如 egreg 所说,如果您不使用组外的标签(如{figure}
),则不会有问题...