7

Say I have an index such as:

1. Chapter
  1.1 Section
  1.2 Section
2. Chapter
3. Chapter

and I number my theorems as

\newtheorem{theorem}{Theorem}[section]

with the last theorem in 1.2 being Theorem 1.2.5. Then the first theorem in chapter two will be 2.0.6.

My first question is: is this really a feature and not a bug? Is there a situation where this is the preferred behavior?

My second question is about how to fix it. I would like the theorems in Chapter 2 to be 2.1, 2.2, etc while keeping the theorems in Chapter 1 to appear as 1.1.1, 1.1.2, etc. I can manually do it various ways (see here) by putting in code in individual chapters. But I shouldn't have to do such a thing, should I? I would really like to have a solution where the format of the numbering is determined entirely in the preamble.

Here is a MWE:

\documentclass[12pt]{report}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]

\begin{document}
 \begin{chapter}{Chapter 1}
  \begin{section}{Secton 1.1}
   \begin{theorem}
    asdf
   \end{theorem}
   \begin{theorem}
    asdf
   \end{theorem}
  \end{section}
 \end{chapter}
 \begin{chapter}{Chapter 2}
  \begin{theorem}
   asdf
  \end{theorem}
 \end{chapter}
\end{document}
6
  • 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
    Apr 16, 2014 at 21:50
  • This the default behaviour (which answers the second question). The preferred behaviour most likely depends on the document. In your case, I would use \newtheorem{theorem}{Theorem}[chapter] rather (answering the first).
    – Werner
    Apr 16, 2014 at 21:55
  • @Werner: Well shoot, I completely misunderstood the meaning of the optional parameter [chapter] (or [section]). Thanks. This is a bad question.
    – RghtHndSd
    Apr 16, 2014 at 21:57
  • @Werner: Whoops, spoke too soon. I still want numbers such as 1.2.1 when there is a section within a chapter. Your recommendation does not have this.
    – RghtHndSd
    Apr 16, 2014 at 22:00
  • @RghtHndSd: I know. My suggestion is to stick to something that works across all of your chapters (with/without sections). And that is to use \newtheorem{theorem}{Theorem}[chapter]. It would also be consistent. It would be possible to devise a numbering that works in both instances, but that would not be consistent in terms of its representation.
    – Werner
    Apr 16, 2014 at 22:02

2 Answers 2

9

The following conditions on the value of section, inserting it into the theorem numbering as needed:

enter image description here

\documentclass[12pt]{report}
\usepackage{amsthm,amsmath}
\newtheorem{theorem}{Theorem}[section]
\numberwithin{theorem}{section}% Reset theorem counter with every section
\numberwithin{theorem}{chapter}% Reset theorem counter with every chapter

\renewcommand{\thetheorem}{%
  \ifnum\value{section}=0 
    \thechapter% "no section"
  \else
    \thesection% at least within a section
  \fi%
  .\arabic{theorem}}

\begin{document}

\chapter{First chapter}
\section{First section}
\begin{theorem}
asdf. See Theorem~\ref{abc} and~\ref{def}.
\end{theorem}
\begin{theorem}\label{abc}
asdf
\end{theorem}
\section{Second section}
\begin{theorem}
asdf
\end{theorem}
\begin{theorem}
asdf
\end{theorem}

\chapter{Second chapter}
\begin{theorem}\label{def}
asdf
\end{theorem}

\end{document}

Note that you have to consider that theorem counters are reset with every \chapter and \section, otherwise you'd have Theorem 2.3 starting off in Chapter 2 in the above example. Also, if you have a theorem inside the "introductory" part of a chapter that eventually will contain a section, then you'll still receive the "reduced" numbering.

0
3

Perhaps a little 'programing' helps to maintain section countering for theorems when there is a section and to drop it, when there is no section!

\documentclass[12pt]{report}
\usepackage{amsthm}
\usepackage{etoolbox}
\newtheorem{theorem}{Theorem}[section]

\makeatletter
\@addtoreset{theorem}{chapter}%
\@addtoreset{theorem}{section}%
\makeatother

\let\OriginalTheTheorem\thetheorem
\renewcommand{\thetheorem}{%
\ifnumequal{\number\value{section}}{0}{\thechapter.\arabic{theorem}}{%
\OriginalTheTheorem}}

\begin{document}
 \begin{chapter}{Chapter 1}
  \begin{section}{Secton 1.1}
   \begin{theorem}
    asdf
   \end{theorem}
   \begin{theorem}
    asdf
   \end{theorem}
  \end{section}
 \end{chapter}
 \begin{chapter}{Chapter 2}
  \begin{theorem}
   asdf
  \end{theorem}
 \end{chapter}
\end{document}

enter image description here

enter image description here

3
  • Thanks for the answer, this does help, but unfortunately the first theorem of chapter 2 is 2.3 and not 2.1.
    – RghtHndSd
    Apr 16, 2014 at 22:19
  • @RghtHndSd: Yes, I forgot that condition, I working out another solution.
    – user31729
    Apr 16, 2014 at 22:20
  • @RghtHndSd: I used a similar style compared to Werners solution, using the direct \@addtoreset way.
    – user31729
    Apr 16, 2014 at 22:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .