我想在 LaTeX 中创建章节和小节,同时我需要在章节中将定理数设为 1.1。和 1.2 等。并且,在第一个小节中,我想要定理数为 1.1.1 和 1.1.2。在小节 2 中,我想要定理数为 1.2.1。和 1.2.2。此外,在小节 2 中,我想要添加一些注释和推论,因此我需要将定理数设为 1.2.3 和 1.2.4。我该怎么办?
答案1
您可以使用 LaTeX 2ε-kernel 来玩\@addtoreset
。
源2e.pdf说:
\@addtoreset{⟨foo⟩}{⟨bar⟩}
:添加计数器⟨foo⟩到计数器列表\cl@bar
时重置计数器⟨酒吧⟩呈阶梯状。
为了确保放入 .pdf 文件中的目标名称的唯一性,hyperref 包重新定义了\@addtoreset
另外的重新定义,以提供以下值:\theH⟨foo⟩
⟨酒吧⟩各自。\theH⟨bar⟩
\documentclass[a4paper]{scrartcl}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheoremstyle{break}
{\topsep}{\topsep}%
{\upshape}{}%
{\bfseries}{}%
{\newline}{}%
\theoremstyle{break}
\newtheorem{MyNiceTheorem}{Theorem}[subsection]% Use subsection to ensure uniqueness of destination-names in case of using hyperref.
\AtBeginDocument{%
% Let's number theorems within sections and subsections
\def\theMyNiceTheorem{\ifnum\value{subsection}<1 \thesection\else\thesubsection\fi.\arabic{MyNiceTheorem}}%
\csname @addtoreset\endcsname{MyNiceTheorem}{section}%
\csname @addtoreset\endcsname{MyNiceTheorem}{subsection}% <- Do this \@addtoreset as the last one to ensure uniqueness of destination-names in case of using hyperref.
}%
\newtheorem{MyNiceRemark}[MyNiceTheorem]{Remark}
\newtheorem{MyNiceCorollary}[MyNiceTheorem]{Corollary}
\begin{document}
\noindent Cross-referencing:
\verb|\ref{FirstSectionTheorem}|: \ref{FirstSectionTheorem}
\verb|\ref{FirstSubSectionTheorem}|: \ref{FirstSubSectionTheorem}
\verb|\ref{SecondSubSectionTheorem1}|: \ref{SecondSubSectionTheorem1}
\verb|\ref{SecondSubSectionTheorem2}|: \ref{SecondSubSectionTheorem2}
\verb|\ref{SecondSectionTheorem}|: \ref{SecondSectionTheorem}
\verb|\ref{FirstSectionCorollary}|: \ref{FirstSectionCorollary}
\verb|\ref{FirstSubSectionCorollary}|: \ref{FirstSubSectionCorollary}
\verb|\ref{SecondSubSectionCorollary1}|: \ref{SecondSubSectionCorollary1}
\verb|\ref{SecondSubSectionCorollary2}|: \ref{SecondSubSectionCorollary2}
\verb|\ref{SecondSectionCorollary}|: \ref{SecondSectionCorollary}
\verb|\ref{FirstSectionRemark}|: \ref{FirstSectionRemark}
\verb|\ref{FirstSubSectionRemark}|: \ref{FirstSubSectionRemark}
\verb|\ref{SecondSubSectionRemark1}|: \ref{SecondSubSectionRemark1}
\verb|\ref{SecondSubSectionRemark2}|: \ref{SecondSubSectionRemark2}
\verb|\ref{SecondSectionRemark}|: \ref{SecondSectionRemark}
\noindent\hrulefill
\section{first section}
\begin{MyNiceTheorem}\label{FirstSectionTheorem}%
Theorem in first section
\end{MyNiceTheorem}
\begin{MyNiceCorollary}\label{FirstSectionCorollary}%
Corollary in first section
\end{MyNiceCorollary}
\begin{MyNiceRemark}\label{FirstSectionRemark}%
Remark in first section
\end{MyNiceRemark}
\subsection{first subsection}
\begin{MyNiceTheorem}\label{FirstSubSectionTheorem}%
Theorem in first subsection
\end{MyNiceTheorem}
\begin{MyNiceCorollary}\label{FirstSubSectionCorollary}%
Corollary in first subsection
\end{MyNiceCorollary}
\begin{MyNiceRemark}\label{FirstSubSectionRemark}%
Remark in first subsection
\end{MyNiceRemark}
\subsection{second subsection}
\begin{MyNiceTheorem}\label{SecondSubSectionTheorem1}%
First theorem in second subsection
\end{MyNiceTheorem}
\begin{MyNiceCorollary}\label{SecondSubSectionCorollary1}%
First corollary in second subsection
\end{MyNiceCorollary}
\begin{MyNiceRemark}\label{SecondSubSectionRemark1}%
First remark in second subsection
\end{MyNiceRemark}
\begin{MyNiceTheorem}\label{SecondSubSectionTheorem2}%
Second theorem in second subsection
\end{MyNiceTheorem}
\begin{MyNiceCorollary}\label{SecondSubSectionCorollary2}%
Second corollary in second subsection
\end{MyNiceCorollary}
\begin{MyNiceRemark}\label{SecondSubSectionRemark2}%
Second remark in second subsection
\end{MyNiceRemark}
\section{second section}
\begin{MyNiceTheorem}\label{SecondSectionTheorem}%
Theorem in second section
\end{MyNiceTheorem}
\begin{MyNiceCorollary}\label{SecondSectionCorollary}%
Corollary in second section
\end{MyNiceCorollary}
\begin{MyNiceRemark}\label{SecondSectionRemark}%
Remark in second section
\end{MyNiceRemark}
\end{document}
答案2
您可以使用两个命令来创建定理,一个用于章节以下的定理,一个用于小节以下的定理,并相应地设置计数器。
\documentclass[a4paper]{scrartcl}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheoremstyle{break}
{\topsep}{\topsep}%
{\upshape}{}%
{\bfseries}{}%
{\newline}{}%
\theoremstyle{break}
\newtheorem{sectheo}{Theorem}[section]
\newtheorem{subsectheo}{Theorem}[subsection]
\begin{document}
\section{first section}
\begin{sectheo}
first section theorem
\end{sectheo}
\subsection{first subsection}
\begin{subsectheo}
first subsection theorem
\end{subsectheo}
\subsection{second subsection}
\begin{subsectheo}
second subsection theorem
\end{subsectheo}
\end{document}