0

I want the theorems to be numerated considering the depth, namely:

Chapter 1.

Theorem 1.1.

Section 1.1.

Theorem 1.1.1.

Subsection 1.1.1.

Theorem 1.1.1.1.

Theorem 1.1.1.2.

Theorem 1.1.1.3.

I have used different theorem types like

\newtheorem{th}{Theorem}[chapter]
\newtheorem{thh}{Theorem}[section]
\newtheorem{thhh}{Theorem}[subsection]

but if I change part of a section into a subsection I have to change all the theorem types within.

Is there any way to unify this?

1
  • Can you provide a complete, minimal example that replicates your current behaviour? What \documentclass are you using? What package are you using for creating your \newtheorems? How do you add the trailing period . to your numbering?
    – Werner
    Commented Feb 1, 2018 at 0:33

1 Answer 1

2

The following code updates \thetheorem - the counter representation of the theorem counter/environment - with a prefix that depends on the current sectional unit:

enter image description here

\documentclass{report}

\newtheorem{theorem}{Theorem}

\makeatletter
\newcommand{\updatetheoremprefixfor}[1]{%
  \expandafter\expandafter\expandafter\let\expandafter\csname old#1\expandafter\endcsname\csname #1\endcsname
  \@namedef{#1}{\renewcommand{\thetheorem}{\csname the#1\endcsname.\arabic{theorem}}
  \setcounter{theorem}{0}%
  \csname old#1\endcsname}}
\makeatother

\updatetheoremprefixfor{chapter}
\updatetheoremprefixfor{section}
\updatetheoremprefixfor{subsection}
\updatetheoremprefixfor{subsubsection}

\begin{document}

\chapter{A chapter}
\begin{theorem}
This is a theorem within a \verb|\chapter|.
\end{theorem}

\section{A section}
\begin{theorem}
This is a theorem within a \verb|\section|.
\end{theorem}

\subsection{A subsection}
\begin{theorem}
This is a theorem within a \verb|\subsection|.
\end{theorem}
\begin{theorem}
This is a theorem within a \verb|\subsection|.
\end{theorem}
\begin{theorem}
This is a theorem within a \verb|\subsection|.
\end{theorem}

\section{A section}
\begin{theorem}
This is a theorem within a \verb|\section|.
\end{theorem}
\begin{theorem}
This is a theorem within a \verb|\section|.
\end{theorem}

\subsection{A subsection}
\begin{theorem}
This is a theorem within a \verb|\subsection|.
\end{theorem}

\end{document}
7
  • I just added, verbatim, in the preamble as you have here. I also added into my document a few theorems as in the example above. The document processes just fine, with no errors, but no theorems are visible (the document is no different with and without the theorems). Here is what I added to the text:\begin{theorem} test \end{theorem} \begin{theorem} test 2 \end{theorem} \subsubsection{Homework Hint} \begin{theorem} test 3 \end{theorem}
    – Mark
    Commented Feb 7, 2018 at 23:28
  • @Mark: Does you .log end with by saying "x Page(s)` where x is not 0? I just want to confirm that TeX actually created some output... Are you using any additional theorem-related packages? Or perhaps defining your theorem environment using something else (like environ)?
    – Werner
    Commented Feb 7, 2018 at 23:31
  • It says: Output written on Solutions.pdf (11 pages, 90526 bytes).
    – Mark
    Commented Feb 8, 2018 at 3:35
  • @Mark: Well, in order to help you efficiently, you'll have to supply me with code that replicates the problem; something I can't do at the moment.
    – Werner
    Commented Feb 8, 2018 at 8:08
  • Thanks for taking the time. After you asked for the page output, I noticed it was far smaller than the size of the document, so I took out those lines, and the full document processed. When I put them back, it worked. I should have thought of trying this, but you got me started. Thanks again...
    – Mark
    Commented Feb 8, 2018 at 23:12

You must log in to answer this question.

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