Arrow with text above or below in LaTeX
\xrightarrow{text} draws a right arrow that stretches to fit the text above it; \xrightarrow[below]{above} puts text under it as well. It comes from amsmath, and \xleftarrow points left.
LaTeX command
\xrightarrow{\text{text}}Not the symbol you meant? Draw it to find the command →
Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →
The arrow grows with its label, so a long name over an arrow never sticks out past its ends. The text in braces goes above; text in the optional square brackets goes below. For text below only, leave the braces empty: \xrightarrow[]{}.
Labels are set in maths, so words need \text: \xrightarrow{\text{heat}}. mathtools adds the other shapes with the same arguments: \xRightarrow and \xLeftarrow for double arrows, \xleftrightarrow, \xmapsto, and hooked arrows such as \xhookrightarrow.
For a fixed-length arrow with a small label, \overset{f}{\rightarrow} also works, but the arrow does not stretch. For arrows between objects laid out in two dimensions, a commutative diagram, the tikz-cd package is the usual tool.
Double and maps-to arrows with text (mathtools)
Load mathtools, which also loads amsmath, for the other stretching arrows. They take the same arguments as \xrightarrow: text below in square brackets, above in braces.
\usepackage{mathtools}\xRightarrow[\text{below}]{\text{above}}\xmapsto{f}Other forms
\xrightarrow[\text{below}]{\text{above}}text above and below\xleftarrow{f}pointing left\xRightarrow{\text{text}}double arrow, mathtools\xmapsto{f}maps-to arrow, mathtools\overset{f}{\rightarrow}a fixed-length arrowExamples
$A \xrightarrow{f} B \xrightarrow{g} C$labelled maps
$A \xrightarrow[\text{below}]{\text{above}} B$text above and below
$x_n \xrightarrow[n \to \infty]{} x$text below only
$\text{ice} \xrightarrow{\text{heat}} \text{water}$words as the label
$A \xleftarrow{\varphi} B$an arrow pointing left
$P \xRightarrow{\text{lemma 2}} Q$a double arrow with text, mathtools
Tips and common mistakes
- Use
\xrightarrowrather than\oversetwith\rightarrowwhen the label is long: only\xrightarrowstretches. - For text below only, leave the braces empty:
\xrightarrow[below]{}. - Wrap words in
\textso they are upright and keep their spaces. \xrightarrowand\xleftarrowneed amsmath; the double, maps-to and hooked versions need mathtools.- For a diagram of several objects and arrows, use tikz-cd instead of chaining arrows.
Working from handwritten notes?
LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.
See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).
Convert your maths to LaTeX →FAQ
How do I put text above an arrow in LaTeX?
Use \xrightarrow{text}, for example A \xrightarrow{f} B. The arrow stretches to fit the text.
How do I put text above and below an arrow?
Use the optional argument for the text below: \xrightarrow[\text{below}]{\text{above}}.
How do I write a double arrow with text?
Load mathtools and use \xRightarrow{text}, or \xLeftarrow for one pointing left.
Which package does \xrightarrow need?
amsmath. KaTeX supports it too, with no setup.