Was this tutorial helpful?

How to Put Text Above Equal Sign in LaTeX?

You often want to put some text directly over the equal sign in LaTeX when writing proofs, derivations, or step-by-step solutions.

The problem is that many beginners often get stuck because LaTeX does not allow normal superscripts directly on symbols like equals.

This tutorial will show all possible methods to place text over equal signs, from basic to advanced.

Using overset

The overset command is the most common and flexible way to put text above an equal sign. It is part of standard LaTeX math commands and works well for short annotations, but for long text it may look cramped.

\overset{text}{symbol}
  • text

    This is the content that appears above the symbol. It can be short like “def” or longer expressions.

  • symbol

    This is the mathematical symbol where the text will be placed. In this case, it is usually =.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
  \[ a + b \overset{\text{def}}{=} c \]
\end{document}

Using stackrel

The stackrel method is a shorter alternative that also places text above a symbol. It works fine but is less flexible than overset, especially with longer text.

\stackrel{text}{symbol}
  • text

    This is the annotation that goes above the chosen symbol. It can be text or math mode expressions.

  • symbol

    This is the mathematical operator or relation that you want to decorate. For equations, it is often =.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
  \[ x \stackrel{\mathrm{?}}{=} y \]
\end{document}

Using xlongequal from extpfeil

This is the best method for putting text above an equal sign, especially when the text is long. The extpfeil package provides \xlongequal, which automatically stretches the equal sign to match the width of the text.

This makes your equations look much cleaner compared to overset or stackrel.

\xlongequal{text}
  • text

    This is the annotation above the equal sign. The equal symbol itself grows in size to match the text width, keeping the layout balanced.

\documentclass{article}
\usepackage{extpfeil}
\begin{document}
  \[ A \xlongequal{\text{step 1}} B \]
\end{document}

Using custom commands

If you want to use this style often, you can define a custom command with \xlongequal. This makes it quick to insert annotated equal signs without repeating code.

\newcommand{\eqtext}[1]{\xlongequal{\text{#1}}}
  • \newcommand

    This defines a new macro in LaTeX that you can reuse throughout your document.

  • \eqtext

    This is the custom command name. Pass one argument, and it will place that text above an equal sign that automatically resizes.

\documentclass{article}
\usepackage{extpfeil}
\newcommand{\eqtext}[1]{\xlongequal{\text{#1}}}
\begin{document}
  \[ f(x) \eqtext{definition} g(x) \]
\end{document}

Best Practice

While \overset and \stackrel are fine for short annotations, the most reliable method is \xlongequal.

It adapts the equal sign size automatically, making long text labels fit naturally without breaking the balance of the equation.

For frequent use, creating a custom command with \xlongequal is the smartest approach, since it keeps your LaTeX code clean and professional.

Was this tutorial helpful?

Share tutorial

Leave a Comment

Your email address will not be published. Required fields are marked *