# How can I number theorems in introduction without section counter and later with it?

I would like to have my theorems numbered in the following way.

Theorem 1. Blah-blah

Theorem 2. More blah-blah

Section 1.

Theorem 1.1. Special blah

Theorem 1.2. More special blah

Section 2

Theorem 2.1. Another special blah

and so on, preferably using the amsmath package. I've been struggling for a while with this, can anyone suggest a simple solution? I would also like to be able to \label and \ref all theorems.

• What is your document class? Is your introduction an unnumbered section, chapter or whatever else? – Bernard May 16 '14 at 13:50
• Welcome to TeX.SX! You have both amsthm and ntheorem; which of the two packages are you using in your document? – egreg May 16 '14 at 13:54
• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 May 16 '14 at 14:00
• @egreg I use amsthm and optionally I can use any other packages. – domotorp May 16 '14 at 14:44

Here's a simple solution. Define your structures without their counters being subordinate to the section counter and just before the first \section use \numberwithin from the amsmath (or \counterwithin from the chngcntr package) package to add the section counter:

\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}


• Brilliant, such a simple solution and good to know command, thx! – domotorp May 19 '14 at 10:00

You won't have scores of theorems in your introduction, so a soft approach could be

\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}


Alternatively, you can define a generic environment for theorems in the introduction:

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

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


and then state your theorems in the introduction as

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

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


Here's a version that numbers the statements in the introduction and also swaps the numbers.

\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}


• Yes, I suppose introducing an introthm is the simplest solution, probably I will go with this unless anyone has some even simpler method. – domotorp May 16 '14 at 14:46
• Actually, I have just realized that this doesn't work for me because I want to be able to label and reference these theorems. – domotorp May 17 '14 at 13:13
• @domotorp If they have no number, how can you reference them? – egreg May 17 '14 at 16:56
• They have. In the intro they are numbered without section and after I would like them numbered with section, as in the example given in my question. – domotorp May 18 '14 at 6:30
• @domotorp They aren't numbered in my version; however, I'll add one with numbers as you wish. – egreg May 18 '14 at 8:26

Here is a solution that does what you want, I think. It uses the titlesec package, for it allows different formatting for numbered and unnumbered sections, and etoolbox to easily define a suitable boolean, numsect' that I set to true for numbered section, and false for the unnumbered, thanks to titlesec. The I redefine the formatting of the theorem label differently, according to the valeue of this boolean.

As the theorem counter is not reset at a new unnumbered section, I had to incorporate it in the unnumbered section formatting.

\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}
`