1

I would like my numbering of theorems to be like "Theorem 1.2.3.4" where 1 is the chapter, 2 is the section, 3 is the subsection, and 4 refers to the fourth theorem in this subsection.

A solution is using \numberwithin{mytheorem}{subsection}: Theorem numbering as chapter.section.subsection.theorem number

However, if I place a theorem in a section, so not in a subsection, I get "Theorem 1.2.0.4". Is it possible to get "Theorem 1.2.4" in this case?

Carucel
  • 1,035
  • 2
    Not without some serious reprogramming (or various handheld adjustments) , you should reconsider this numbering scheme, it might confuse your readers more than it would help them. – daleif Jun 05 '16 at 14:14
  • @daleif, Is it really that strange a question? So I cant use \newtheorem{thm}{mytheorem}[section] and put some mytheorem's in sections and some in chapters? (because then I get "Theorem 0.1") – Carucel Jun 05 '16 at 20:10
  • @Carucel: You could change the resetting counter from time to time manually. –  Jun 06 '16 at 14:04

1 Answers1

2

As daleif mentionted: The numbering scheme can confuse readers, but here's a solution.

The command \clevercnt checks whether (sub)section counters are greater than zero and uses the full format then, otherwise another, shorter format is used.

\documentclass{book}

\usepackage{amsmath}
\usepackage{amsthm}

\newtheorem{thm}{Theorem}[subsection]
%\numberwithin{thm}{subsection}


\newcommand{\clevercnt}[1]{%
  \ifnum\value{subsection} > 0 
  \thesubsection.\arabic{thm}%
  \else
  \ifnum\value{section} > 0
  \thesection.\arabic{thm}%
  \else
  \thechapter.\arabic{thm}%
  \fi
  \fi
}


\renewcommand{\thethm}{\clevercnt{thm}}


\begin{document}

\chapter{Foo}
\begin{thm}

\end{thm}

\chapter{Second}
\section{Foo}
\begin{thm}
Hello
\end{thm}

\chapter{Second}
\section{Foo}
\begin{thm}
Hello
\end{thm}

\section{other}
\subsection{Foobar}
\begin{thm}
Hello
\end{thm}


\end{document}