Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Apologies if this is duplicate but couldn't find it.

I have a document using amsmath for chapter, section & subsection numbering, & everything (theorems, lemmas etc) uses the same numbering system.

I have one chapter that has no sections or subsections (this does make sense, honest, its a 5-6 page theorem that doesn't fit with anything else). The problem is the numbering here starts at 4.0.13 (because I haven't reset the subsection counter, presumably).

I have two options - either set it to 4.1.1 or even better, have only two part numbering in this chapter so that the theorems/lemmas can be numbered 4.1, 4.2 etc etc. I have read quite a few posts about \numberwithin & \counterwithin but am pretty confused.

Example below - here the thm in chapter 2 is number 2.0.3 but I want it to be 2.1.1 or preferably just 2.1.

\documentclass{scrreprt}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}

\theoremstyle{plain}% default
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{prop}[thm]{Proposition}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\newtheorem{conj}{Conjecture}[section]
\newtheorem{exmp}{Example}[section]
\theoremstyle{remark}
\newtheorem*{rem}{Remark}
\newtheorem*{note}{Note}
\newtheorem{case}{Case}
\makeatletter\@addtoreset{case}{thm}\makeatother
\makeatletter
\def\thm@space@setup{%
 \thm@preskip=\parskip \thm@postskip=0pt}
\makeatother

\makeatletter\@addtoreset{case}{lem}\makeatother
\makeatletter
\def\thm@space@setup{%
\thm@preskip=\parskip \thm@postskip=0pt}
\makeatother

\begin{document}

\begin{chapter}{chap title}
\begin{section}{title blah}
\begin{thm}
hello
\end{thm}
\begin{subsection}{title blahh}
\begin{lem} 
hi
\end{lem}
\end{subsection}
\end{section}
\end{chapter}

\begin{chapter}{chap title 2}
\begin{thm}
hello again
\end{thm}
\end{chapter}

\end{document}
share|improve this question
1  
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}. –  Christian Hupfer Aug 4 at 21:29
2  
In the MWE, you might just include chapter and section commands. We have to be able to reproduce the problem in order to understand and fix it. My main question is, why is a new chapter not resetting the subsection counter? –  Andrew Cashner Aug 4 at 21:33
    
Included most of preamble incase something else is messing it up. –  Zoe Kelly Aug 4 at 21:41
    
@ZoeKelly: The 2.0.3 stems from not having a section in the 2nd chapter, therefore subsection counter is not reset at all. Your thm environment resets only with sections, so it is frozen to 3 in that example. –  Christian Hupfer Aug 4 at 21:42
    
Yes - I am trying to have a chapter with only one section so it seems silly to create a section as it doesn't need a title & I don't want to number it. Sorry if I'm not being clear in what I'm attempting to do.. –  Zoe Kelly Aug 4 at 21:45

2 Answers 2

There are no chapter, section or subsection environments. Don't use \begin{chapter} and similar constructions, even if they appear to work.

You can make the decision about the numbering automatic: if the section counter is zero, as it is after \chapter, the theorems will be numbered “chapter.theorem”, otherwise “chapter.section.theorem”. No manual resetting is needed for chapters where theorems are inside sections.

I removed the setting to \thm@space@setup because I don't really understand what they're supposed to do.

\documentclass{scrreprt}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}

\theoremstyle{plain}% default
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{prop}[thm]{Proposition}

\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\newtheorem{conj}{Conjecture}[section]
\newtheorem{exmp}{Example}[section]

\theoremstyle{remark}
\newtheorem*{rem}{Remark}
\newtheorem*{note}{Note}
\newtheorem{case}{Case}[thm]

\makeatletter
\@addtoreset{thm}{chapter}
\makeatother
\renewcommand{\thethm}{%
  \ifnum\value{section}=0
    \thechapter.%
  \else
    \thesection.%
  \fi
  \arabic{thm}%
}
\renewcommand{\thecase}{\arabic{case}}

\begin{document}

\chapter{chap title}
\section{title blah}
\begin{thm}
hello
\end{thm}

\subsection{title blahh}
\begin{lem} 
hi
\end{lem}

\chapter{chap title 2}
\begin{thm}
hello again
\end{thm}

\end{document}

Note how it's easier to reset the case number with every theorem.

enter image description here

enter image description here

share|improve this answer

Use the chngcntr package and a manual reset before the 2nd chapter, via \setcounter{thm}{0}.

There might be some resetting afterwards necessary!

\documentclass{scrreprt}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{chngcntr}%

\theoremstyle{plain}% default
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{prop}[thm]{Proposition}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\newtheorem{conj}{Conjecture}[section]
\newtheorem{exmp}{Example}[section]
\theoremstyle{remark}
\newtheorem*{rem}{Remark}
\newtheorem*{note}{Note}
\newtheorem{case}{Case}
\makeatletter
\@addtoreset{case}{thm}
\makeatother
\makeatletter
\def\thm@space@setup{%
 \thm@preskip=\parskip \thm@postskip=0pt}
\makeatother

\makeatletter\@addtoreset{case}{lem}\makeatother
\makeatletter
\def\thm@space@setup{%
\thm@preskip=\parskip \thm@postskip=0pt}
\makeatother

\begin{document}

\begin{chapter}{chap title}
\begin{section}{title blah}
\begin{thm}
hello
\end{thm}
\begin{subsection}{title blahh}
\begin{lem} 
hi
\end{lem}
\end{subsection}
\end{section}
\end{chapter}


%%%% My addition:
\setcounter{thm}{0}
\begin{chapter}{chap title 2}
%%%% My addition:

\counterwithin{thm}{chapter}
\begin{thm}
hello again
\end{thm}
\end{chapter}

\end{document}

enter image description here

share|improve this answer
    
Brilliant, thank you (didn't affect next chapter numbering either). –  Zoe Kelly Aug 4 at 21:52
    
@ZoeKelly: That's due to your usage of \begin{chapter} perhaps. As egreg stated in his solution, one should not use \begin{chapter} etc. but \chapter etc. –  Christian Hupfer Aug 4 at 22:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.