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}Hat accent over one symbol.
\widehat{xyz}Wide hat that stretches over several symbols.
\hat{\theta}_{s+1}Hat on the letter, subscript after the accent.
\hat{\imath}, \hat{\jmath}Unit vectors on dotless i and j.
\hat{\mathbf{n}}Unit vector in bold.
\check{x}Inverted hat (háček).
- Text mode, no math preview
\textasciicircumA literal caret ^ in running text.
- Text mode, no math preview
\^{o}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.
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
LaTeX\hat{\beta} = (X^\top X)^{-1} X^\top yPredicted value
LaTeX\hat{y} = \hat{\beta}_0 + \hat{\beta}_1 xUnit vector
LaTeX\hat{\mathbf{u}} = \frac{\mathbf{u}}{\|\mathbf{u}\|}Hat with a subscript
LaTeX\hat{\theta}_{s+1} = \hat{\theta}_s - \eta \nabla L(\hat{\theta}_s)Fourier transform
LaTeX\hat{f}(\xi) = \int_{-\infty}^{\infty} f(x) \, e^{-2\pi i x \xi} \, dxWide hat
LaTeX\widehat{ABC} \quad \widehat{x + y}Basis vectors
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}\hatis 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,\jmathand\textasciicircumare built in; no package needed.MathJax and KaTeX
MathJax and KaTeX support
\hatand\widehat; they typically draw\widehatwider 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.
Related LaTeX reference
- Tilde (~) in LaTeXWhy ~ prints a space, how to get a visible tilde in text, the \tilde and \widetilde accents, and \sim in math.
- Vector in LaTeX\vec{v} and \overrightarrow{AB}, bold vectors with \mathbf and \boldsymbol, unit vectors, column and row vectors, and norms.
- Dot in LaTeX\cdot, \ldots, \cdots, \vdots, \ddots, \dot{x} and \bullet, and which dot fits which context.
- LaTeX equation editorSymbol panel, live preview, and PNG, SVG, MathML or Word export.
- All LaTeX reference pagesSymbols, math structures and text formatting in one list.
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