# Numbering within sections

I am writing up lecture notes for a class and it gets quite long and has many theorems, lemmas, etc. I would like to know how to get the numbering of these environments to reset at the start of each section. As it is now, these environments are getting numbered in the hundreds at it looks bad. Below are all the relevant parts of my preamble. I have looked into this a non-trivial amount and asked the professor whose class the notes came from for help and the best we got is including "\numberwithin{equation}{section}" in the preamble. This did not solve the problem unfortunately. Is there a simple fix so that theorems in section n are numbered n.1, n.2, etc.?

\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{preamble}
\usepackage{listings}
\usepackage{enumitem}
\geometry{tmargin=.75in, bmargin=.75in, lmargin=.75in, rmargin = .75in}
\title{Ma 121a Lecture Notes}
\author{Instructor: Dr. Professor\\ Notes written by Me}
\numberwithin{equation}{section}
\begin{document}
\maketitle
\vspace{.25in}
\section*{Lecture 1}
\begin{definition}
This is Definition 1.1.
\end{definition}
\begin{definition}
This is definition 1.2.
\end{definition}
\section*{Lecture 2}
\begin{theorem}
This is Theorem 2.3. But I would like it to be Theorem 2.1.
\end{theorem}


The above is a MWE. What follows below is the preamble I load in separately as a .sty file using \usepackage{preamble}. The MWE will not work without the preamble.

\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{wasysym}
\usepackage{verbatim}
\usepackage{bbm}
\usepackage{graphics}
\usepackage{geometry}
\usepackage{latexsym}
\usepackage{epsfig}
\usepackage{bm}
\usepackage{xspace}
\usepackage{times}
\usepackage{listings}
\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{conjecture}[theorem]{Conjecture}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

• To elaborate a little more, we also had issues with numbering across sections, for example a theorem in section would be say Theorem 1.50, but we fixed this partially by adding "\addtocounter{section}{1}" after each new section. Now it would read Theorem 4.50, but if it is the first theorem in section 4, I would want it to be numbered Theorem 4.1. Jul 1, 2020 at 2:26
• Is this helpful? Jul 1, 2020 at 7:06
• Please provide an MWE that we can process. Having deleted the \usepackage{preamble} line I get that \geometry is undefined. I haven't bothered to try anything else after that. --- GOM Jul 1, 2020 at 17:28
• @PhysMath You have shown the code for your preamble.sty but you have shown no code for the body of the document --- no \section, no theorems, lemmas, etc. Your MWE should start with \documentclass... and end with \end{document} that we can process that shows your problem. We can make wild guesses as to what you have done, but they will be wild and probably nothing to do with what you have actually done. Jul 2, 2020 at 17:36
• Don't do \section*{title} and \addtocounter{section}{1}! Use \section if there is numbering involved. At least use \stepcounter{section}. Jul 2, 2020 at 23:56

\newtheorem{theorem}{Theorem}[section]


so the theorem counter will be reset for every numbered section, but not for unnumbered sections even when the section counter gets a value assigned. As a minimal change, replace

\addtocounter{section}{1}


with

\refstepcounter{section}


which resets the theorem counter and has the added benefit that you can use \label and \ref to refer to other lectures.

On the other hand, it looks like you really do have numbered sections, but don't want the formatting used by regular sections. I suggest you switch to the numbered \section command and omit any explicit setting of the section counter. Declare

\renewcommand\thesection{Lecture~\arabic{section}}
\renewcommand\thetheorem{\arabic{section}.\arabic{theorem}}


This inserts the word "Lecture" before the section number, rather than following it. Of course you don't want the word in the theorem number, so you would redefine that to skip \thesection and use \arabic{section} directly. At each lecture declare a section without title

\section{}


This handles resetting the theorem counter, displays the lecture title as you wanted, allows rearrangement without manual editing, allows explanatory titles for lectures

\section{Welcome class} % for lecture 1


\renewcommand\numberline[1]{%
\begingroup
\sbox\@tempboxa{#1 }%
\ifdim\wd\@tempboxa<\@tempdima
\wd\@tempboxa=\@tempdima
\fi
\usebox\@tempboxa
\endgroup
}


because the standard definition does not like section "numbers" as wide as "Lecture 2".

• This is excellent, thanks! Works as advertised. Jul 3, 2020 at 5:54