30

I am trying to number my theorems as follows:

Theorem 1.A. First part of a theorem.

Theorem 1.B. Second part of the theorem.

Theorem 2. A theorem with no parts.

The following almost works:

\newtheorem{theorem}{Theorem}
\newtheorem{theorempart}{Theorem}[theorem]

But it does not increment the theorem counter as I want, so that

\begin{theorempart}First part of a theorem.
\end{theorempart}

\begin{theorempart}Second part of the theorem.
\end{theorempart}

\begin{theorem}A theorem with no parts.
\end{theorem}

gives:

Theorem 0.1. First part of a theorem.

Theorem 0.2. Second part of the theorem.

Theorem 1. A theorem with no parts.

Also, I don't know how to get the part-number to be a letter instead of a number.

I am using MiKTeX.

1

2 Answers 2

25

The model I used is that of the subequations environment in amsmath:

\documentclass{article}

\makeatletter
\newenvironment{subtheorem}[1]{%
  \def\subtheoremcounter{#1}%
  \refstepcounter{#1}%
  \protected@edef\theparentnumber{\csname the#1\endcsname}%
  \setcounter{parentnumber}{\value{#1}}%
  \setcounter{#1}{0}%
  \expandafter\def\csname the#1\endcsname{\theparentnumber.\Alph{#1}}%
  \ignorespaces
}{%
  \setcounter{\subtheoremcounter}{\value{parentnumber}}%
  \ignorespacesafterend
}
\makeatother
\newcounter{parentnumber}

\newtheorem{thm}{Theorem}

\begin{document}

\begin{thm}\label{thm:one}
One
\end{thm}

\begin{subtheorem}{thm}\label{thm:two}
\begin{thm}\label{thm:twoA}
Two, first part
\end{thm}

\begin{thm}\label{thm:twoB}
Two, second part
\end{thm}
\end{subtheorem}

\begin{thm}\label{thm:three}
Three
\end{thm}

\ref{thm:one}, \ref{thm:two}, \ref{thm:twoA}, \ref{thm:twoB}, \ref{thm:three}.

\end{document}

You enclose the part in which the theorems have to be "subnumbered" in the subtheorem environment, which takes as argument the name of the theorem-like environment you want to affect.

The \label commands are not mandatory, but you can see that you can also set a "global" label for the subnumbered theorem.

4
  • @egreg This is great, but somehow the hyperlinks generated with \cref{} no longer work. I generated Theorems 5.A and 5.B like this, but any link to 5.A jumps to Theorem 1 and any link to 5.B jumps to Theorem 2. Any idea how to fix that?
    – mimuller
    Commented Nov 1, 2015 at 4:44
  • 1
    @ItsmeMimi This warrants a new question.
    – egreg
    Commented Nov 1, 2015 at 9:17
  • 1
    @egreg Done: tex.stackexchange.com/questions/276238/…. Thanks for the code though, this already helped me a lot!
    – mimuller
    Commented Nov 2, 2015 at 18:11
  • While this is great (and I've already given it a +1 from a past visit), I feel this issue with the false anchors should be made clearer. I had put this code into my preamble, not having really read the comments. I was then having this issue, and coming back to this question saw that I wasn't the first. It's perhaps worth noting at the top of the answer that the referencing doesn't work as some would like, but that it was fixed (with only a very minor change) in the question linked by @ItsmeMini. As always egreg, thanks for the extremely useful code! :)
    – Sam OT
    Commented Jul 23, 2018 at 18:17
0

Another way of fixing this easily is by the below code. However, one need to reset the subtheorem counter after each new theorem.

\documentclass{article}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem{subtheorem}{Theorem}
\renewcommand{\thesubtheorem}{\thetheorem.\Alph{subtheorem}}
\setcounter{theorem}{1}

\begin{document}
   
\begin{subtheorem}First part of a theorem.
\end{subtheorem}

\begin{subtheorem}Second part of the theorem.
\end{subtheorem}

\begin{theorem}A theorem with no parts.
\end{theorem}

\setcounter{subtheorem}{0}
\begin{subtheorem}Second part of the theorem.
\end{subtheorem}

\end{document}

This gives:
Theorem 1.A. First part of a theorem.
Theorem 1.B. Second part of the theorem.
Theorem 2. A theorem with no parts.
Theorem 2.A. Second part of the theorem.

You must log in to answer this question.

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