Hat in LaTeX

Put a hat over a letter with \hat{x} in math mode, which gives x̂. For a hat that spans several symbols use \widehat{xyz}. To print the caret character ^ itself, write \textasciicircum in text, because a bare ^ starts a superscript.

Hat commands

  • \hat{x}
    x ^

    Hat accent over one symbol.

  • \widehat{xyz}
    x y z ^

    Wide hat that stretches over several symbols.

  • \hat{\theta}_{s+1}
    θ ^ s + 1

    Hat on the letter, subscript after the accent.

  • \hat{\imath}, \hat{\jmath}
    ı ^ , ȷ ^

    Unit vectors on dotless i and j.

  • \hat{\mathbf{n}}
    n ^

    Unit vector in bold.

  • \check{x}
    x ˇ

    Inverted hat (háček).

  • \textasciicircum
    Text mode, no math preview

    A literal caret ^ in running text.

  • \^{o}
    Text mode, no math preview

    Circumflex accent in text, giving ô.

Try it live

Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.

Templates

Hat accent examples

Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.

  • Estimator

    β ^ = ( X ⊤ X ) − 1 X ⊤ y
    LaTeX
    \hat{\beta} = (X^\top X)^{-1} X^\top y
  • Predicted value

    y ^ = β ^ 0 + β ^ 1 x
    LaTeX
    \hat{y} = \hat{\beta}_0 + \hat{\beta}_1 x
  • Unit vector

    u ^ = u ∥ u ∥
    LaTeX
    \hat{\mathbf{u}} = \frac{\mathbf{u}}{\|\mathbf{u}\|}
  • Hat with a subscript

    θ ^ s + 1 = θ ^ s − η ∇ L ( θ ^ s )
    LaTeX
    \hat{\theta}_{s+1} = \hat{\theta}_s - \eta \nabla L(\hat{\theta}_s)
  • Fourier transform

    f ^ ( ξ ) = ∫ − ∞ ∞ f ( x ) e − 2 π i x ξ d x
    LaTeX
    \hat{f}(\xi) = \int_{-\infty}^{\infty} f(x) \, e^{-2\pi i x \xi} \, dx
  • Wide hat

    A B C ^ x + y ^
    LaTeX
    \widehat{ABC} \quad \widehat{x + y}
  • Basis vectors

    v = 3 ı ^ − 2 ȷ ^ + k ^
    LaTeX
    \mathbf{v} = 3\hat{\imath} - 2\hat{\jmath} + \hat{k}

\hat or \widehat?

\hat has a fixed small width and is centered over its argument, so over two or more letters it looks too short. \widehat grows with its contents up to a limit (in the standard fonts, about three or four letters). Use \hat for single symbols such as x̂, ŷ, β̂.

Hats with subscripts and on i, j

Put only the letter inside the accent and the subscript outside: \hat{\theta}_{s+1}, not \hat{\theta_{s+1}}. The second form centers the hat over the whole subscripted group.

On i and j the hat collides with the dot, so use the dotless letters \imath and \jmath: \hat{\imath}, \hat{\jmath}.

Printing the caret ^

^ is the superscript character, so it never prints by itself. In text use \textasciicircum; in code samples \verb|^| or the listings package. \^{} also prints a caret but places it high, as an accent over nothing. In math, a caret-shaped operator is \wedge (∧), which is a different symbol.

Common mistakes

  • The hat should sit on the letter only; otherwise it centers over the letter and its subscript.

    Instead of
    \hat{\theta_{s+1}}
    Write
    \hat{\theta}_{s+1}
  • \hat is too narrow for two letters.

    Instead of
    \hat{xy}
    Write
    \widehat{xy}
  • The hat and the dot of i overlap; the dotless i avoids it.

    Instead of
    \hat{i}
    Write
    \hat{\imath}
  • \^ is a text accent; in math mode LaTeX reports "Command \^ invalid in math mode".

    Instead of
    $\^{x}$
    Write
    $\hat{x}$

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    \hat, \widehat, \check, \imath, \jmath and \textasciicircum are built in; no package needed.

  • MathJax and KaTeX

    MathJax and KaTeX support \hat and \widehat; they typically draw \widehat wider than pdfLaTeX, so long arguments may look different on the web.

  • Microsoft Word

    Write the variable with its hat here and use Copy for Word to paste an editable Word equation.

Hat accent in LaTeX: questions

How do you do a hat in LaTeX?
Use \hat{x} in math mode for x̂.
How do I write y hat?
Write \hat{y}, for example \hat{y} = \hat{\beta}_0 + \hat{\beta}_1 x.
How do I make a wide hat over several letters?
Use \widehat{AB}. It stretches over its contents, up to a few characters wide.
How do I type the caret symbol ^?
In text use \textasciicircum; in code \verb|^|. In math, ^ always starts a superscript.

Have the formula as a picture?

Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.

Convert an image to LaTeX