Theorems, Lemmas and Proofs in LaTeX: amsthm, \newtheorem and the QED Symbol
LaTeX has no built-in theorem environment. You create one with \newtheorem, and the amsthm package adds the styles, the proof environment and the end-of-proof symbol. This guide sets that up step by step: numbered and unnumbered theorems, lemmas that share the theorem counter, the three built-in styles, proofs that end with the QED box in the right place (even after an equation or a list), changing the symbol, referencing theorems with \ref and cleveref, colored theorem boxes with tcolorbox, and the errors that come up along the way.
Setting Up amsthm
Load amsmath first, then amsthm, then declare the environments you need. The second argument of \newtheorem is the word that is printed; the first is the name you use in \begin:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
Every bounded monotone sequence of real numbers converges.
\end{theorem}
\begin{proof}
Let $(a_n)$ be increasing and bounded above, and let $L = \sup_n a_n$.
For any $\varepsilon > 0$ there is an $N$ with $a_N > L - \varepsilon$,
and then $L - \varepsilon < a_n \le L$ for all $n \ge N$.
\end{proof}
\end{document}This prints Theorem 1. followed by the statement in italics, then Proof. and the argument in upright type, ending with a hollow square (□) at the right margin. An optional argument adds a name or attribution to the heading: \begin{theorem}[Monotone Convergence] prints Theorem 1 (Monotone Convergence).
The AMS classes (amsart, amsbook) already load amsthm; with any other class you load it yourself. The order matters: if amsmath is loaded after amsthm, the proof environment's handling of the QED symbol in displayed equations breaks (“The \qedhere command may not work correctly here”).
Numbering: Within Sections and Shared Counters
A bare \newtheorem{theorem}{Theorem} numbers theorems 1, 2, 3 across the whole document. Most papers number within sections (Theorem 2.1, 2.2) and most books within chapters. The optional argument after the printed name does this:
\newtheorem{theorem}{Theorem}[section] % Theorem 1.1, 1.2, 2.1, ...
% \newtheorem{theorem}{Theorem}[chapter] % per chapter, in book/reportThe second question is whether lemmas, propositions and corollaries get their own sequence or share the theorem counter. Sharing is the norm in mathematics: it lets a reader find “Lemma 2.3” between Theorem 2.2 and Corollary 2.4 without searching. An optional argument before the printed name makes an environment use another environment's counter:
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma} % shares the theorem counter
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
% Definitions and examples often get their own counters
\newtheorem{definition}{Definition}[section]
\newtheorem{example}{Example}[section]You cannot use both optional arguments at once: an environment either shares a counter or defines its own, and the shared one inherits the [section] reset from the environment it follows.
Unnumbered theorems
The starred form defines an environment with no number at all, used for famous named results and for remarks:
\newtheorem*{fermat}{Fermat's Last Theorem}
\newtheorem*{remark}{Remark}
\begin{fermat}
No three positive integers $a$, $b$, $c$ satisfy $a^n + b^n = c^n$
for any integer $n > 2$.
\end{fermat}To put the number before the name (“2.1 Theorem” instead of “Theorem 2.1”), issue \swapnumbers before the \newtheorem declarations it should affect.
Theorem Styles: plain, definition and remark
amsthm ships three styles. \theoremstyle switches the current style, and each \newtheorem that follows picks it up:
| Style | Heading | Body | Use for |
|---|---|---|---|
plain (default) | Bold | Italic | Theorem, Lemma, Proposition, Corollary, Conjecture |
definition | Bold | Upright | Definition, Example, Problem, Exercise |
remark | Italic | Upright | Remark, Note, Notation, Case |
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem*{notation}{Notation}The italic body of the plain style is why definitions get their own style: a definition full of italic text with italic variables is hard to read, and the word being defined cannot be emphasised. Inside an italic theorem, use \textup or \emph (which toggles back to upright) for text that should not be slanted.
Custom styles with \newtheoremstyle
For a journal that wants, say, small caps headings or a line break after the heading, define your own style. The nine arguments are: name, space above, space below, body font, indent, heading font, punctuation after the heading, space after the heading (or \newline), and a heading specification (leave empty for the default):
\newtheoremstyle{scthm} % name
{\topsep} % space above
{\topsep} % space below
{\itshape} % body font
{} % indent
{\scshape} % heading font
{.} % punctuation after heading
{\newline} % space after heading: \newline or a length
{} % heading spec (empty = default)
\theoremstyle{scthm}
\newtheorem{claim}{Claim}The proof Environment and the QED Symbol
proof prints an italic Proof. heading and places the end-of-proof symbol, by default a hollow box (\openbox), flush right on the last line. The symbol is often called the QED symbol, tombstone or Halmos, after quod erat demonstrandum and the mathematician who popularised the box.
Change the heading for one proof with the optional argument. This is the standard way to prove a theorem stated earlier, or to split a proof into parts:
\begin{proof}[Proof of Theorem~\ref{thm:main}]
...
\end{proof}
\begin{proof}[Sketch of proof]
...
\end{proof}
% The default word, for all proofs (e.g. for another language)
\renewcommand{\proofname}{Beweis}\qedhere: the symbol after an equation or a list
If a proof ends with a displayed equation, the box lands on its own line below the equation, which looks wrong. Put \qedhere at the end of the last display and amsthm moves the symbol onto that line instead:
\begin{proof}
Expanding the square and collecting terms,
\begin{align*}
(a+b)^2 &= a^2 + ab + ba + b^2 \\
&= a^2 + 2ab + b^2. \qedhere
\end{align*}
\end{proof}
\begin{proof}
Both directions are immediate:
\begin{itemize}
\item If $x \in A$ then $x \in A \cup B$.
\item If $x \in A \cup B$ and $x \notin B$ then $x \in A$. \qedhere
\end{itemize}
\end{proof}\qedhere works in equation, align, gather, their starred forms, \[ ... \], and in the last item of a list. With a numbered equation the symbol is placed to the left of the equation number. If the proof simply ends with text, you need nothing: the symbol appears automatically.
Changing the QED symbol
The symbol is stored in \qedsymbol. Redefine it in the preamble; a filled square from amssymb is the most common replacement:
\usepackage{amssymb}
\renewcommand{\qedsymbol}{$\blacksquare$} % filled square
\renewcommand{\qedsymbol}{$\square$} % hollow square from amssymb
\renewcommand{\qedsymbol}{\rule{0.5em}{0.5em}} % filled square, no package
\renewcommand{\qedsymbol}{QED} % the letters
\renewcommand{\qedsymbol}{} % no symbol at allThe amsthm default, \openbox, and the amssymb \square look almost the same; \blacksquare is the filled version. In plain text or Unicode-aware editors the dedicated character is ∎, U+220E “End of Proof”, which you can use with XeLaTeX or LuaLaTeX and a font that contains it. To put the symbol somewhere by hand, outside a proof environment, use the \qed command.
Referencing Theorems
A \label inside the environment (after \begin) records the theorem number, exactly as for equations and figures. \ref prints the number; cleveref adds the environment's name:
\usepackage{hyperref} % optional, for clickable references
\usepackage{cleveref} % after hyperref and amsthm
\begin{theorem}[Pythagoras]
\label{thm:pythagoras}
In a right triangle, $a^2 + b^2 = c^2$.
\end{theorem}
\begin{lemma}
\label{lem:aux}
...
\end{lemma}
By Theorem~\ref{thm:pythagoras} ... % Theorem 1.1
By \cref{thm:pythagoras} ... % theorem 1.1
\Cref{thm:pythagoras,lem:aux} show ... % Theorem 1.1 and Lemma 1.2cleveref learns the name of each environment from its \newtheorem declaration. To change the wording or capitalise it everywhere, set it once: \crefname{theorem}{Theorem}{Theorems}, or load cleveref with the capitalise option. The same labels work with \autoref from hyperref, which prints “Theorem 1.1” using \theoremautorefname.
thmtools, ntheorem and Theorem Boxes with tcolorbox
thmtools
thmtools is a layer on top of amsthm with a key–value interface. It is handy when you want many environments with slightly different settings, and it adds a list of theorems:
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[name=Theorem, numberwithin=section]{theorem}
\declaretheorem[name=Lemma, numberwithin=section]{lemma}
\declaretheorem[name=Remark, style=remark, numbered=no]{remark}
\listoftheorems % like \listoffigures, for theoremsThe sibling=theorem key is thmtools' equivalent of the [theorem] optional argument for sharing a counter. Note that thmtools has not kept pace with recent LaTeX kernel releases: on the newest TeX Live, shared counters fail with Command \c@lemma already defined as soon as thmtools is loaded. If you hit that, drop thmtools and use plain amsthm, which handles everything in this guide.
ntheorem
ntheorem is an older alternative to amsthm with its own styles and automatic end marks (\usepackage[thmmarks, amsmath]{ntheorem}). It works, but it is not compatible with amsthm; pick one package per document. New documents should use amsthm, which every journal class understands.
Colored theorem boxes with tcolorbox
For lecture notes and textbooks, tcolorbox can draw each theorem in a framed, shaded box. \newtcbtheorem defines a numbered environment that takes a title and a label suffix as arguments:
\usepackage[most]{tcolorbox}
\newtcbtheorem[number within=section]{boxthm}{Theorem}{%
colback=blue!5, colframe=blue!60!black,
fonttitle=\bfseries, separator sign={.}
}{thm}
\begin{boxthm}{Pythagoras}{pyth}
In a right triangle, $a^2 + b^2 = c^2$.
\end{boxthm}
See Theorem~\ref{thm:pyth}. % the label is prefix:suffixUse an empty first argument, \begin{boxthm}{}{pyth}, for a theorem with no name. tcolorbox theorems have their own counters, so if you mix them with amsthm environments, give them the amsthm counter with use counter*=theorem in the options (use counter= without the star would overwrite amsthm's numbering format).
Common Errors
| Message or symptom | Cause | Fix |
|---|---|---|
| Environment theorem undefined | No \newtheorem in the preamble; amsthm provides proof only | Add \newtheorem{theorem}{Theorem} before \begin{document} |
| Environment proof undefined | amsthm not loaded | \usepackage{amsthm} |
| Command \proof already defined | \newtheorem{proof}{Proof} with amsthm loaded, or an AMS class that already defines it | Delete the \newtheorem; use the built-in proof environment |
| QED box on its own line after an equation | The proof ends with a display and nothing after it | Add \qedhere inside the last display or list item |
| Two QED symbols | \qed written manually inside a proof environment | Remove \qed; use \qedhere if placement is the issue |
Theorems numbered 0.1, 0.2 in an article | [section] used but no \section precedes the theorem | Add a section, or number without [section] |
| Lemma numbering restarts at 1 | Lemma has its own counter | \newtheorem{lemma}[theorem]{Lemma} to share the theorem counter |
| “The \qedhere command may not work correctly here”, QED in the wrong place | amsthm loaded before amsmath | Load amsmath first, then amsthm |
\theoremstyle has no effect | It was issued after the \newtheorem it was meant for | Put \theoremstyle before the declarations it applies to |
\cref prints ?? or the wrong name | Not compiled twice, or \label placed before \begin | Compile twice; put \label inside the environment |
Complete Example
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[hidelinks]{hyperref}
\usepackage{cleveref}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\renewcommand{\qedsymbol}{$\blacksquare$}
\begin{document}
\section{Divisibility}
\begin{definition}
\label{def:even}
An integer $n$ is \emph{even} if $n = 2k$ for some integer $k$.
\end{definition}
\begin{lemma}
\label{lem:square}
If $n$ is even, then $n^2$ is even.
\end{lemma}
\begin{proof}
Write $n = 2k$ as in \cref{def:even}. Then
\[
n^2 = 4k^2 = 2(2k^2),
\]
which is even. \qedhere
\end{proof}
\begin{theorem}[Euclid]
\label{thm:euclid}
There are infinitely many primes.
\end{theorem}
\begin{proof}[Proof of \Cref{thm:euclid}]
Suppose $p_1, \dots, p_n$ are all the primes and let
$N = p_1 p_2 \cdots p_n + 1$. No $p_i$ divides $N$, so $N$ has a
prime factor not in the list, a contradiction.
\end{proof}
\begin{corollary}
\label{cor:unbounded}
The set of primes is unbounded.
\end{corollary}
\begin{remark}
\Cref{cor:unbounded} follows from \cref{thm:euclid} because a finite
set of integers is bounded. \Cref{lem:square} was not needed.
\end{remark}
\end{document}Compile twice. Definition 1.1, Lemma 1.2, Theorem 1.3 and Corollary 1.4 share one counter, the remark is unnumbered, and every proof ends with a filled square.
Quick Reference
| Task | Command |
|---|---|
| Load the package | \usepackage{amsmath} then \usepackage{amsthm} |
| Numbered theorem | \newtheorem{theorem}{Theorem} |
| Numbered within sections | \newtheorem{theorem}{Theorem}[section] |
| Share the theorem counter | \newtheorem{lemma}[theorem]{Lemma} |
| Unnumbered | \newtheorem*{remark}{Remark} |
| Style | \theoremstyle{plain} / definition / remark before \newtheorem |
| Named theorem | \begin{theorem}[Pythagoras] |
| Proof | \begin{proof} ... \end{proof} |
| Custom proof heading | \begin{proof}[Proof of Theorem~\ref{thm:main}] |
| QED after an equation or list item | \qedhere at the end of the display or item |
| Filled QED square | \renewcommand{\qedsymbol}{$\blacksquare$} (amssymb) |
| No QED symbol | \renewcommand{\qedsymbol}{} |
| Manual QED symbol | \qed |
| Reference a theorem | \label{thm:x} inside; \ref{thm:x} or \cref{thm:x} |
| Number before name | \swapnumbers before \newtheorem |
| Boxed theorem | \newtcbtheorem{boxthm}{Theorem}{options}{thm} (tcolorbox) |
| List of theorems | \listoftheorems (thmtools) |
Next Steps
Theorems in place? These guides cover what goes inside them:
- Equation Numbering and Referencing – \label, \eqref, align and split for the equations in your proofs
- Mathematical Expressions – Fractions, roots, operators and the amsmath environments
- Greek Letters & Math Symbols – Set notation, logic symbols and arrows for theorem statements
- Integrals, Sums & Limits – Big operators and limits in displayed math
- LaTeX Hyperlinks – Clickable theorem references with hyperref and cleveref
- Learn LaTeX – Complete beginner tutorial covering all the basics
Free LaTeX Tools
- LaTeX Preview – Test theorem styles with a live PDF preview
- Math to LaTeX Converter – Turn handwritten or typed math into LaTeX
- LaTeX Symbols Reference – Browse math operators and special characters
Related Articles
Degree Symbol: How to Type ° on Keyboard, Mac, iPhone, Word, LaTeX
Best LaTeX Editors for Mac: Complete Comparison Guide 2026
From Crixet to Prism: The Evolution of AI-Powered LaTeX Editing
How to Create a Professional Resume in LaTeX (Complete Guide 2026)
Write proofs faster with AI
Octree's AI editor sets up amsthm for you, places the QED symbol correctly, and compiles your document in seconds.
Try Octree Free →