Theorems and Proofs in LaTeX: amsthm, \newtheorem and the QED Symbol

Quick answer

  • Package: \usepackage{amsthm}, loaded after amsmath.
  • Define a theorem: \newtheorem{theorem}{Theorem}[section] in the preamble, then \begin{theorem} ... \end{theorem}. Lemmas sharing its numbers: \newtheorem{lemma}[theorem]{Lemma}.
  • Styles: \theoremstyle{plain} (italic body, theorems), definition (upright, definitions and examples), remark (italic heading), each placed before its \newtheorem.
  • Proof: \begin{proof} ... \end{proof} ends with the end of proof symbol □ automatically.
  • Filled QED square: \renewcommand\qedsymbol{$\blacksquare$} (needs amssymb).
  • Symbol after an equation: \qedhere at the end of the last line; outside a proof, \qed.

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.

How to Define a Theorem in LaTeX: amsthm and \newtheorem

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/report

The 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 and Definition Styles: plain, definition and remark

amsthm ships three styles. \theoremstyle switches the current style, and each \newtheorem that follows picks it up:

StyleHeadingBodyUse for
plain (default)BoldItalicTheorem, Lemma, Proposition, Corollary, Conjecture
definitionBoldUprightDefinition, Example, Problem, Exercise
remarkItalicUprightRemark, 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.

A definition environment

A definition is declared exactly like a theorem, only under the definition style, so the body is upright and the term being defined can stand out in italics:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}

\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\begin{document}
\section{Groups}

\begin{definition}[Group]
  A \emph{group} is a set $G$ with an associative operation
  $G \times G \to G$, an identity element and an inverse for
  every element.
\end{definition}

\end{document}

This prints Definition 1.1 (Group). with the body in upright type. Without the \theoremstyle line the body would be italic and the emphasised word group would flip to upright, which reads backwards.

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

proof prints an italic Proof. heading, sets the argument in upright type and ends it with the end-of-proof symbol (covered in the next section). 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}

End of Proof Symbol in LaTeX (∎, □): \qedsymbol, \blacksquare and \qedhere

The end of proof symbol is the small square that marks where a proof finishes. It is also called the QED symbol (after quod erat demonstrandum), the tombstone, or the Halmos, after the mathematician who popularised it. In amsthm it is stored in \qedsymbol, and the proof environment prints it flush right on the last line automatically. The default is a hollow square, \openbox (□).

You wantWrite
Hollow square □ (default)nothing: \begin{proof} ... \end{proof}
Filled square ■\renewcommand{\qedsymbol}{$\blacksquare$} (amssymb)
The letters QED\renewcommand{\qedsymbol}{QED}
Symbol on the last line of an equation or list\qedhere at the end of that line
Symbol outside a proof environment\qed (amsthm) or \hfill$\square$ (amssymb)

Changing the QED symbol to a filled square

Redefine \qedsymbol once in the preamble and every proof uses the new symbol. 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 all

Use only one of these lines. The amsthm default, \openbox, and the amssymb \square look almost the same; \blacksquare is the filled version.

\qedhere: the symbol after an equation or a list

If a proof ends with a displayed equation, an align or a list, the box lands on its own line below it, which looks wrong. Put \qedhere at the end of the last line 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. Numbered displays are the awkward case: in equation the symbol drops below the equation number, and in a numbered align it takes the place of the last line’s number. If a proof ends with a numbered display, use the starred form or close with a short sentence after it. If the proof simply ends with text, you need nothing: the symbol appears automatically.

The symbol without a proof environment

With amsthm loaded, \qed prints \qedsymbol flush right at the point where you type it, for example after a solution or a worked example. Without amsthm there is no \qedsymbol; push a square to the right margin with \hfill instead:

% amsthm loaded: same symbol as in proof environments
\noindent\textit{Solution.} The answer is $x = 2$. \qed

% no amsthm: amssymb for \square or \blacksquare
\noindent\textit{Proof.} Immediate from the definition. \hfill$\square$

The ∎ character, ntheorem and thmtools

In Unicode the end of proof symbol is ∎, U+220E “END OF PROOF”; the hollow square □ is U+25A1 “WHITE SQUARE”. You can type either character directly with XeLaTeX or LuaLaTeX and a font that contains it, but in pdfLaTeX use the commands above. thmtools builds on amsthm, so \qedsymbol, \qed and \qedhere work unchanged, and \declaretheorem[qed=$\blacksquare$]{example} adds an end mark to other environments. ntheorem with the thmmarks option places end marks itself, set per environment with \theoremsymbol{$\blacksquare$}.

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.2

cleveref 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 theorems

The 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:suffix

Use 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 symptomCauseFix
Environment theorem undefinedNo \newtheorem in the preamble; amsthm provides proof onlyAdd \newtheorem{theorem}{Theorem} before \begin{document}
Environment proof undefinedamsthm not loaded\usepackage{amsthm}
Command \proof already defined\newtheorem{proof}{Proof} with amsthm loaded, or an AMS class that already defines itDelete the \newtheorem; use the built-in proof environment
QED box on its own line after an equationThe proof ends with a display and nothing after itAdd \qedhere inside the last display or list item
Two QED symbols\qed written manually inside a proof environmentRemove \qed; use \qedhere if placement is the issue
Theorems numbered 0.1, 0.2 in an article[section] used but no \section precedes the theoremAdd a section, or number without [section]
Lemma numbering restarts at 1Lemma 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 placeamsthm loaded before amsmathLoad amsmath first, then amsthm
No counter 'chapter' defined\newtheorem{theorem}{Theorem}[chapter] in an article, which has no chaptersUse [section] in article; [chapter] only in book and report
\theoremstyle has no effectIt was issued after the \newtheorem it was meant forPut \theoremstyle before the declarations it applies to
\cref prints ?? or the wrong nameNot compiled twice, or \label placed before \beginCompile 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

TaskCommand
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)

Frequently Asked Questions

How do I put the QED symbol in LaTeX?

Load amsthm and write the proof inside \begin{proof} ... \end{proof}; the end of proof symbol (a hollow square) is added flush right on the last line automatically. For a filled square load amssymb and put \renewcommand{\qedsymbol}{$\blacksquare$} in the preamble. Outside a proof environment, type \qed (amsthm) or \hfill$\square$ (amssymb).

Why does the QED box appear on the wrong line?

When a proof ends with a displayed equation, an align or a list, amsthm puts the symbol on a new line below it. Write \qedhere at the end of the last equation line or list item to move the symbol up onto that line. Load amsmath before amsthm, or \qedhere may not work in displays.

How do you define a theorem in LaTeX?

Load amsthm in the preamble and declare the environment with \newtheorem{theorem}{Theorem}: the first argument is the environment name, the second the word that is printed. Then write \begin{theorem} ... \end{theorem} in the document. Add [section] at the end, \newtheorem{theorem}{Theorem}[section], to number theorems 1.1, 1.2 within each section.

How do I create a definition environment in LaTeX?

Switch to the definition style before declaring it: \theoremstyle{definition} followed by \newtheorem{definition}{Definition}[section]. The definition style prints a bold heading and an upright body, so the defined term can be set in italics with \emph. Use \newtheorem{definition}[theorem]{Definition} instead if definitions should share the theorem numbering.

What is the end of proof symbol called?

It is called the QED symbol, the tombstone, or the Halmos (after Paul Halmos, who introduced it to mathematics). Unicode encodes the filled version as ∎ (U+220E END OF PROOF). In LaTeX the amsthm proof environment prints a hollow square □ by default, and \renewcommand{\qedsymbol}{$\blacksquare$} switches it to the filled ∎ style.

How do I number theorems, lemmas and corollaries in one sequence?

Declare the theorem first and give the others its counter in square brackets between the two names: \newtheorem{theorem}{Theorem}[section], then \newtheorem{lemma}[theorem]{Lemma} and \newtheorem{corollary}[theorem]{Corollary}. Theorem 2.1 is then followed by Lemma 2.2 and Corollary 2.3.

Next Steps

Theorems in place? These guides cover what goes inside them:

Free LaTeX Tools

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 →