167

This is difficult for me to explain, but how do I put words over a symbol? For instance, I want to add words over an equal sign. Anyone know the command/syntax for that?

Also adding ^ doesn't cut it..., I want the text to appear ON TOP.

1
  • 2
    What text do you want above the equal sign? Commented Sep 25, 2012 at 23:55

4 Answers 4

130

You can use a combination of \stackrel and \mathclap (from the mathtools package):

\documentclass{article}
\usepackage{mathtools}

\newcommand\myeq{\stackrel{\mathclap{\normalfont\mbox{def}}}{=}}

\begin{document}

\begin{align*}
a &\myeq b \\
  &=c \\
  &= d.
\end{align*}

\end{document}

enter image description here

If using mathtools is not an option, you can use a \makebox of width 0pt:

\documentclass{article}
\usepackage{amsmath}

\newcommand\myeq{\mathrel{\stackrel{\makebox[0pt]{\mbox{\normalfont\tiny def}}}{=}}}

\begin{document}

\begin{align*}
a &\myeq b \\
  &=c \\
  &= d.
\end{align*}

\end{document}

enter image description here

Even better, if amsmath has been loaded, is to use \overset instead of \stackrel; a little example using \tiny\sffamily for "def" :

\documentclass{article}
\usepackage{amsmath}

\newcommand\myeq{\mathrel{\overset{\makebox[0pt]{\mbox{\normalfont\tiny\sffamily def}}}{=}}}

\begin{document}

\begin{align*}
a &\myeq b \\
  &=c \\
  &= d.
\end{align*}

\end{document}

enter image description here

Inside the argument for \mbox one can use some of the font modifiers, as I did in my second and third examples.

Particularly, I don't like this kind of notation (it's not really necessary); you should consider if you really need the text above the equal sign.

9
  • Wouldn't be \mbox better than \text in this case, so that the def is still upshape even e.g. in theorem?
    – yo'
    Commented Sep 26, 2012 at 6:43
  • @tohecz -- if upshape is always desired, then the expression (as in this case) is probably an operator name, so that approach would be better. Commented Sep 26, 2012 at 12:44
  • @tohecz yes; I updated my answer. Thanks you. Commented Sep 26, 2012 at 14:47
  • I'd prefer \overset to \stackrel; instead of \mbox I'd use \mathrm or \textnormal.
    – egreg
    Commented Sep 26, 2012 at 15:52
  • @egreg; right; I've added an example with \overset; thank you. I kept the \mbox since I wanted to illustrate changes to the font for the text (which the OP seems to want to apply according to a comment to the other answer). Commented Sep 26, 2012 at 17:23
185
$\stackrel{sometext}{=}$

if sometext is not intended to be in math mode then write \text{sometext} within. (\text is available in amsmath package)

$\stackrel{\text{sometext}}{=}$

blessings

5
  • Is it possible to change the size and fonts of the text? I tried {\small sometext|, but it didn't work. Also the syntax isn't working very well in \begin{align}...\end{align} environment
    – Lemon
    Commented Sep 25, 2012 at 23:36
  • 6
    @jak: Please include a minimal working example (MWE) that shows your current usage and highlight clearly what you want or need changed. Do so via an edit to your post.
    – Werner
    Commented Sep 25, 2012 at 23:55
  • 1
    @jak: You can't use \small in mathmode. Have a look at Gonzalo's answer, he successfully uses \tiny there... Commented Sep 26, 2012 at 1:19
  • @Hawk now with my edit, by using the command \text inside, you can use any text command you want ;) Commented Feb 18, 2016 at 15:54
  • tex.stackexchange.com/a/39230/75621 suggests to use \underset instead of \stackrel, because the former is "obsolete".
    – AXO
    Commented Oct 21, 2019 at 16:10
100
$\overset{\mathrm{def}}{=}$

\overset is available in amsmath package.

Good luck.

3
  • 10
    And with the corresponding \underset option, this the simplest answer. Commented Jan 13, 2018 at 0:51
  • 1
    By far the most simple way.
    – mins
    Commented Feb 23, 2023 at 12:36
  • ... and I cannot see the difference between \overset and \stackrel here. Commented Jun 11 at 9:49
6

All answers here suppose that you are using LaTeX (??). If it is not true then there is standard plain TeX macro \buildrel for doing this. The syntax is \buildrel (what above) \over (relation)

$a \buildrel \rm def \over = b$
\bye

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .