Over/under decorations

How far does \widehat stretch? The answer is: to 1.44 em and no further. LaTeX's wide hat has only three glyphs in the font cmex10, measuring 5.55557 pt, 10.00002 pt and 14.44447 pt at 10 pt. There is no fourth, so put it over something long like \widehat{f(x+y+z)} and the hat simply stops growing and perches in the middle. \overline, \overbrace and \overrightarrow, by contrast, are assembled from rules and stretch without limit. Everything you can set above or below an expression falls on one side or the other of that line — stretchy or fixed — and picking the wrong side is what breaks the look. This page draws the boundary with measurements, and carries it through to \overset, \stackrel and \xrightarrow.

Stretchy or fixed: the difference between \hat, \widehat and \overline

The three differ in where they get their shape from. In fontmath.ltx, \hat is an accent from operators (the ordinary roman text font) sized for a single letter, \widehat is a variable-width accent from largesymbols (cmex10), and \overline is not a character at all but a rule. So \hat{x} is fixed at one letter's width, \widehat{xy} picks the largest of three glyphs that still fits, and \overline{xyz} is drawn to exactly the width of its contents. Measured: apply \overline to material 60 pt wide and the rule comes out at exactly 60 pt. Apply \widehat to the same material and the hat stays 14.44447 pt.

GroupCommandsBehaviour
rules & braces\overline \underline \overbrace \underbraceassembled from rules — stretch without limit
extensible arrows\overrightarrow \overleftarrow \overleftrightarrowthe shaft is filled by \rightarrowfillno limit
wide accents\widehat \widetildethree glyphs only — capped at 14.44447 pt
fixed accents\hat \tilde \bar \vec \dot \ddot and the restsized for one letter — no stretching at all
arbitrary material\overset \underset \stackrel \xrightarrowplace any symbol, set small; only \xrightarrow stretches its shaft

A line across the whole expression: \overline and \underline

\overline{…} draws a rule above its argument and \underline{…} below it, exactly as wide as the contents. Both are standard LaTeX and need no package. They mark a complement, a complex conjugate, or simply the signal “treat this stretch as one thing”. The rule from \underline is positioned to clear descenders — letters such as y and g that hang below the baseline — so it never cuts through them. They are also among the very few decorations that nest cleanly: \overline{\overline{z}} sets as a proper double bar. Measured, \overline{z} is 6.30544 pt tall and the doubled form 8.30533 pt — about 2 pt per layer.

latex
\[
  \overline{a + b} = \overline{a} + \overline{b}, \qquad
  \underline{x + y}, \qquad \overline{\overline{z}} = z
\]

Marking a range with a brace: \overbrace{…}^{…} and \underbrace{…}_{…}

A horizontal brace runs across the top or bottom of an expression, and ^ or _ attaches a label just beyond it. \overbrace and \underbrace are standard LaTeX, and the brace stretches to the full width of the contents. The reason you can label them at all is that their definition in fontmath.ltx ends in \mathop{…}\limits. Being a \mathop is what makes ^ and _ available; the written-in \limits is what keeps the label above or below even in inline math. In other words, \overbrace carries its label by the same machinery as a summation sign.

latex
\[
  \underbrace{1 + 2 + \cdots + n}_{n \text{ terms}}
  = \frac{n(n+1)}{2}
  \qquad
  \overbrace{x + x + \cdots + x}^{k}
\]

When a label contains words, wrap it in \text{…} (from amsmath), since you are inside math mode. And that \limits has a price. Measured, $\underbrace{a+b}_{n}$ has a depth of 14.19992 pt. A plain $a+b$ has 0.83333 pt, and the \baselineskip of a 10 pt document is 12 pt — so an inline brace sinks deeper than a whole line of leading and forces the surrounding lines apart. That is why braces belong in displayed equations. If you must have one inline, \underbrace{a+b}\nolimits_{n} moves the label to the right and brings the depth back to 8.53328 pt. As a neighbouring topic, \substack — for stacking two conditions under a summation sign — belongs to the page on big operators.

Where \widehat and \widetilde stop growing

The cap is 14.44447 pt, roughly 1.44 em in a 10 pt document. The declaration in fontmath.ltx, \DeclareMathAccent{\widehat}{\mathord}{largesymbols}{"62}, points at glyph "62 of cmex10, which chains onward to "63 and "64. Measured with \fontcharwd, the three widths are 5.55557 pt, 10.00002 pt and 14.44447 pt. TeX picks the largest glyph that is not wider than the nucleus, so anything narrower than 14.44447 pt gets one of the smaller hats, and anything wider — however much wider — keeps the largest one, centred. The three \widetilde glyphs have the same widths. So \widehat{x} and \widehat{xy} look natural, while \widehat{f(x+y+z)} leaves the hat covering only part of the expression.

latex
\[
  \widehat{x + y} \neq \hat{x} + \hat{y}, \qquad
  \widetilde{ab}, \qquad
  \overline{f(x+y+z)}   % use a rule once the hat runs out
\]

An arrow over the expression: \overrightarrow, and the \vec trap

To write the directed segment AB, use \overrightarrow{AB}, not \vec{AB}. \vec is declared in fontmath.ltx as \DeclareMathAccent{\vec}{\mathord}{letters}{"7E} — a fixed accent sized for one letter — so \vec{AB} drops a small arrow effectively over the B alone. \overrightarrow, by contrast, builds the arrow itself: the shaft is \rightarrowfill, which tiles minus signs with \cleaders and caps them with a head, so it has no upper limit on width. Leftward is \overleftarrow, both ways \overleftrightarrow. The under-side forms \underrightarrow, \underleftarrow and \underleftrightarrow require amsmath.

latex
\usepackage{amsmath}   % needed for \underrightarrow and friends
\[
  \vec{a} \quad \text{vs.} \quad \overrightarrow{AB},
  \qquad \overleftrightarrow{PQ}, \qquad \underrightarrow{x}
\]

Fixed accents for a single letter: \dot, \bar, \hat and \imath

Fixed accents are tools for decorating a single letter: \dot for a time derivative, \ddot for a second one, \bar for a mean or a conjugate, \hat for an estimator, \tilde for an approximation — the marks that turn up constantly in science and engineering. All are standard LaTeX; applied to several letters they do not stretch but sit centred at the size of one symbol. There is one classical convention: putting a mark on i or j collides with the letter's own dot, so build on the dotless \imath and \jmath. Write \hat{\imath} and you get the caret alone, cleanly placed.

CommandWhat it placesStretches?
\hata caret (circumflex)fixed; the wide version is \widehat
\tildea tildefixed; the wide version is \widetilde
\bara short bar (macron)fixed; for a whole expression use \overline
\veca small rightward arrowfixed; the wide arrow is \overrightarrow
\dot \ddotone dot, two dotsfixed; \dddot and \ddddot need amsmath
\acute \graveacute and grave accentsfixed
\check \brevea háček (ˇ) and a breve (˘)fixed
\mathringa small ring (˚)fixed
\imath \jmathdotless i and jthe base for an accent, as in \hat{\imath}

One warning. Accents do not stack cleanly. Layering two, as in \hat{\vec{x}}, tends to leave the upper mark floating, too high, or off-centre — about the only marks that nest comfortably are the \overline and \underline from earlier. If you merely want more dots, use \ddot or amsmath's \dddot and \ddddot. If you genuinely need two different marks, build them explicitly with the \overset of the next section, or hand the job to a dedicated package. For fine adjustment of the position, fontmath.ltx also provides \skew.

latex
\[
  \dot{x}, \quad \ddot{x}, \quad \bar{x}, \quad \hat{p},
  \quad \tilde{a}, \quad \check{s}, \quad \hat{\imath}, \quad \vec{\jmath}
\]

\overset versus \stackrel: measured, they differ by 1.11109 pt

The difference is whether the class of the base is inherited. \stackrel is defined in latex.ltx as \mathrel{\mathop{#2}\limits^{#1}}, so whatever you give it, the result is always a relation. amsmath's \overset uses a helper called \binrel@ to inspect the base and re-emits it as a binary operator if it was one, as a relation if it was one. Measured: a\overset{f}{+}b is 21.79968 pt, exactly matching a\mathbin{+}b, while a\stackrel{f}{+}b is 22.91077 pt, exactly matching a\mathrel{+}b. The 1.11109 pt gap is the difference between a medium space of 4 mu and a thick space of 5 mu, counted on both sides. When the base is already a relation such as =, the two agree — so \overset is the safe default.

latex
\usepackage{amsmath}   % \overset, \underset, \overunderset
\[
  A \overset{f}{\longrightarrow} B, \qquad
  X \underset{n \to \infty}{\longrightarrow} x, \qquad
  a \overset{\text{def}}{=} b, \qquad
  \overunderset{a}{b}{X}
\]

\overset{above}{base} sets any symbol or expression small above the base, and \underset{below}{base} below it. The second argument is the base and the first is what you add; the added material is set in scriptstyle — the size LaTeX uses for scripts — so it comes out small with no effort on your part. To place material both above and below you can nest them, but amsmath also offers \overunderset{above}{below}{base}, which reads better. The difference from the fixed accents is that you choose what goes on top. And note the contrast with scripts: ^ and _ sit at the upper and lower right of a symbol, whereas \overset and \underset place material directly above and below.

Arrows that stretch to their label: \xrightarrow and \xleftarrow

When an arrow needs a name, use amsmath's \xrightarrow{…} rather than \stackrel. The reason is width. With a long label, A\xrightarrow{\text{very long label}}B measures 79.12704 pt, because the shaft itself grows to the width of the label. Put the same label on a \longrightarrow with \stackrel and the whole thing is 72.7536 pt, but the arrow beneath it is still the fixed 37.25343 pt — so the text hangs off both ends of the arrow. \xrightarrow also takes an optional argument in square brackets: \xrightarrow[n \to \infty]{f} puts the name of the map above and the condition below at the same time. The leftward form is \xleftarrow.

latex
\usepackage{amsmath}
% mathtools adds \xLeftarrow, \xhookrightarrow, \xmapsto and more
\[
  A \xrightarrow{\;f\;} B \xleftarrow{\;g\;} C,
  \qquad a_n \xrightarrow[n \to \infty]{} L
\]
  • Decorating a single letter → a fixed accent (\hat, \bar, \dot, \vec)
  • Covering a whole expression\overline, \overrightarrow; \widehat tops out at 14.44447 pt
  • Marking a range with a brace\overbrace{…}^{…}, \underbrace{…}_{…}; keep them in displays
  • An \underbrace inline → its 14.19992 pt depth forces the lines apart; \nolimits moves the label aside
  • Any symbol above or below → amsmath's \overset, \underset, \overunderset
  • Naming an arrow\xrightarrow{…}; \stackrel cannot stretch its shaft
  • Accenting i or j → build on the dotless \imath and \jmath