3

Following the answer to this question, I defined example and solution environments using the thmtools package, which I want to share numbering with the other environments in my document. Here is my MWE:

\documentclass{book}
 \usepackage[margin=.75 in]{geometry}
\usepackage[english = american]{csquotes}
\usepackage{amsmath,amsfonts,amssymb,amsthm,color,srcltx,enumitem,bm,cancel,thmtools}
\usepackage{setspace}
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

%Plain environments:
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{result}[theorem]{Result}
%Definition environments:
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
%Remark environments:
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

%Example and solution environments (from https://tex.stackexchange.com/questions/19947/example-solution-environment):
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
numberwithin=section,
sharenumber=theorem
]{exstyle}
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
headpunct={},
qed=$\blacktriangleleft$,
numbered=no,
sharenumber=theorem
]{solstyle}
\declaretheorem[style=exstyle]{example}
\declaretheorem[style=solstyle]{solution}

\begin{document}
\part{Part 1}
\chapter{Chapter 1}
\section{Section 1}
\begin{definition}
Definition goes here
\end{definition}
\begin{theorem}
Theorem goes here
\end{theorem}
\begin{proposition}
Proposition goes here
\end{proposition}
\begin{lemma}
Lemma goes here
\end{lemma}
\begin{result}
Result goes here
\end{result}
\begin{example}
Example goes here
\end{example}
\end{document}

Notice that I added sharenumber=theorem, an idea I got from the thmtools documentation. The problem is, adding this causes a LaTeX error "Missing \begin{document}". Removing the line sharenumber=theorem makes the error go away, but then I lose the shared numbering.

EthanAlvaree
  • 1,367

1 Answers1

2

First no need to use numberwithin=section in the declaration of extstyle as the example environment is intended to share the same counter as theorem. And theorem is already numbered within section by its definition. Moreover numberwithin key is unknown to \declaretheoremstyle. Same is true for sharenumber key. This key should be passed to \declaretheorem instead of \declaretheoremstyle.

  1. Don't put sharenumber and numberwithin in the \declaretheoremstyle.

  2. Put sharenumber in the \declaretheorem.

Now the full code.

\documentclass{book}
 \usepackage[margin=.75 in]{geometry}
\usepackage[english = american]{csquotes}
\usepackage{amsmath,amsfonts,amssymb,amsthm,color,srcltx,enumitem,bm,cancel,thmtools}
\usepackage{setspace}
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

%Plain environments:
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{result}[theorem]{Result}
%Definition environments:
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
%Remark environments:
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

%Example and solution environments (from http://tex.stackexchange.com/questions/19947/example-solution-environment):
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
%numberwithin=section,              %%<--- remove this as it is unknown here
]{exstyle}
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
headpunct={},
qed=$\blacktriangleleft$,
numbered=no,
%sharenumber=theorem     %% not needed here
]{solstyle}
\declaretheorem[sharenumber=theorem,style=exstyle]{example}
\declaretheorem[style=solstyle]{solution}

\begin{document}
\part{Part 1}
\chapter{Chapter 1}
\section{Section 1}
\begin{definition}
Definition goes here
\end{definition}
\begin{theorem}
Theorem goes here
\end{theorem}
\begin{proposition}
Proposition goes here
\end{proposition}
\begin{lemma}
Lemma goes here
\end{lemma}
\begin{result}
Result goes here
\end{result}
\begin{example}
Example goes here
\end{example}
\end{document}

enter image description here

You can also use sibling=theorem or numberlike=theorem

  • it's sharenumber not sharecounter in last line? I think no such key defined by the package!? – touhami Sep 30 '15 at 06:52
  • @touhami It is defined according to the manual. Please see page 3, line 1 after the example at the top. I have added a screen shot. –  Sep 30 '15 at 06:55
  • @HarishKumar It works like a charm. Thanks for pointing out the mistakes and for your help correcting them! – EthanAlvaree Sep 30 '15 at 07:00
  • @EthanAlvaree You are welcome. :) –  Sep 30 '15 at 07:03
  • I think it's an error of documentation, as you can see your code use sharenumber=theorem not one of 3 keys mentionned but it works, however if you try sharecounter=theorem you will get error (at least I do) – touhami Sep 30 '15 at 07:36
  • @touhami Yes. I too get an error. I will correct. Thanks. –  Sep 30 '15 at 07:40