如何在不使用节计数器的情况下在引言中对定理进行编号,然后在使用节计数器的情况下对定理进行编号?

如何在不使用节计数器的情况下在引言中对定理进行编号,然后在使用节计数器的情况下对定理进行编号?

我希望按照以下方式对我的定理进行编号。

定理 1. 废话

定理 2. 更多废话

第 1 节。

定理 1.1. 特殊废话

定理 1.2. 更多特别的废话

第 2 部分

定理 2.1. 另一个特别的废话

等等,最好使用amsmath包。我为此苦苦挣扎了一段时间,有人能提出一个简单的解决方案吗?我也希望能够\label\ref所有定理。

答案1

这是一个简单的解决方案。定义结构时,不要让它们的计数器从属于节计数器,而只需第一次\section使用\numberwithinamsmath(或者\counterwithinchngcntr包中)包添加计数器section

\documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}

\newtheorem{thm}{Theorem}
\newtheorem{lem}[thm]{Lemma}

\begin{document}

\section*{Introduction}
Some cross-references: \ref{a}, \ref{b}, \ref{c}, \ref{d}, \ref{e}, and \ref{f}.
\begin{thm}\label{a}
test theorem in the introduction
\end{thm}

\begin{lem}\label{b}
test lemma in the introduction
\end{lem}

\begin{thm}\label{c}
test theorem in the introduction
\end{thm}

\numberwithin{thm}{section}
\section{A test numbered section}

\begin{lem}\label{d}
test lemma in a numbered section
\end{lem}

\begin{thm}\label{e}
test theorem in a numbered section
\end{thm}

\begin{thm}\label{f}
test theorem in the introduction
\end{thm}

\end{document}

在此处输入图片描述

答案2

你的引言中不会有大量的定理,因此可以采用一种柔和的方法

\documentclass{article}
\usepackage{amsthm}

\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem*{thm*}{Theorem}

\begin{document}

\section*{Introduction}

In this paper we'll prove the following result.

\begin{thm*}
All numbers are odd.
\end{thm*}

This striking result has several consequences.


\section{Preliminary results}

Here is the most useful lemma.

\begin{lem}
The number $1$ is even.
\end{lem}

\begin{proof}
Everybody can see it.
\end{proof}

Here is a first consequence.

\begin{thm}
All prime numbers are odd.
\end{thm}

\begin{proof}
Since $2=1+1$, $2$ is odd.
\end{proof}

\section{The main result}

We are now ready to prove our main result.

\begin{thm}
All numbers are odd.
\end{thm}

\begin{proof}
Since $0$ is obviously even, $1$ is odd. But $1$ is even, so also
$0$ is odd. A number $n>1$ is a product of primes, hence odd.
\end{proof}

\end{document}

在此处输入图片描述

或者,您可以在简介中为定理定义一个通用环境:

\newcommand{\introthmname}{}
\newtheorem*{introthminn}{\introthmname}

\newenvironment{introthm}[1]
  {\renewcommand{\introthmname}{#1}\begin{introthminn}}
  {\end{introthminn}}

然后在引言中陈述你的定理

\begin{introthm}{Lemma}
The number $1$ is even.
\end{introthm}

\begin{introthm}{Theorem}
All numbers are odd.
\end{introthm}

这是对引言中的陈述进行编号并交换数字的版本。

\documentclass{article}
\usepackage{amsthm}

\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}

\newcommand{\introthmname}{}
\newtheorem{introthminn}{\introthmname}
\newenvironment{introthm}[1]
  {\renewcommand{\introthmname}{#1}\begin{introthminn}}
  {\end{introthminn}}

\swapnumbers

\begin{document}

\section*{Introduction}

In this paper we'll prove the following result.

\begin{introthm}{Theorem}\label{thm:main}
All numbers are odd.
\end{introthm}

This striking result has several consequences.


\section{Preliminary results}

Here's the most useful lemma.

\begin{lem}
The number $1$ is even.
\end{lem}

\begin{proof}
Everybody can see it.
\end{proof}

Here's a first consequence.

\begin{thm}
All prime numbers are odd.
\end{thm}

\begin{proof}
Since $2=1+1$, $2$ is odd.
\end{proof}

\section{The main result}

We are now ready to prove our main result, already stated as 
Theorem~\ref{thm:main} in the introduction.

\begin{thm}
All numbers are odd.
\end{thm}

\begin{proof}
Since $0$ is obviously even, $1$ is odd. But $1$ is even, so also
$0$ is odd. A number $n>1$ is a product of primes, hence odd.
\end{proof}

\end{document}

在此处输入图片描述

答案3

我认为这是一个可以满足您的要求的解决方案。它使用包titlesec,因为它允许对编号和未编号部分进行不同的格式设置,并etoolbox轻松定义一个合适的布尔值“numsect”,我将其设置为 true 表示编号部分,false 表示未编号部分,这要感谢 titlesec。我根据这个布尔值的值以不同的方式重新定义了定理标签的格式。

由于定理计数器不会在新的未编号部分重置,因此我必须将其合并到未编号部分格式中。

\documentclass{article}
\usepackage{amsthm}

\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{etoolbox, chngcntr} %
\newbool{numsect}
\titleformat{name = \section}[hang]{\global\booltrue{numsect}\Large\bfseries}{\arabic{section}.}{0.5em} {}
\titleformat{name = \section, numberless}[hang]{\setcounter{thm}{0}\global\boolfalse{numsect}\Large\bfseries}{}{0pt}{}%

% \renewcommand\thethm{\ifbool{numsect}{\thesection.\arabic{thm}}{\arabic{thm}}}%

\begin{document}

\section*{Introduction}

In this paper we'll prove the following result.

\begin{thm}
All numbers are odd.
\end{thm}

This striking result has several consequences.

\section{Preliminary results}

Here is the most useful lemma.

\begin{lem}
The number $1$ is even.
\end{lem}

\begin{proof}
Everybody can see it.
\end{proof}

Here is a first consequence.

\begin{thm}
All prime numbers are odd.
\end{thm}

\begin{proof}
Since $2=1+1$, $2$ is odd.
\end{proof}

\section{The main result}

We are now ready to prove our main result. \

\begin{thm}
All numbers are odd.
\end{thm}

\begin{proof}
Since $0$ is obviously even, $1$ is odd. But $1$ is even, so also
$0$ is odd. A number $n>1$ is a product of primes, hence odd.
\end{proof}

\section*{Conclusion}

\begin{thm}
Even even numbers are odd.
\end{thm}

\end{document} 

在此处输入图片描述

相关内容