How to Write a Bar in LaTeX

Use \bar{x} for a bar over a single letter (x̄, the sample mean) and \overline{AB} for a bar that spans several characters (a line segment, a complex conjugate of a sum). If you mean the vertical bar |, use | or \vert for absolute values and \mid for "such that" or "divides".

Bars over letters

  • \bar{x}
    x ¯

    Short bar over one character.

  • \overline{AB}
    A B ―

    Bar over the whole group; grows with the content.

  • \underline{x}
    x ―

    The same line below.

  • \bar{\bar{x}}
    x ¯ ¯

    Double bar (grand mean).

  • \vert x \vert
    | x |

    Vertical bars for absolute value; |x| is the same.

  • \{ x \mid x > 0 \}
    { x ∣ x > 0 }

    \mid is the vertical bar with relation spacing.

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

Bar (x̄) and overline 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.

\bar or \overline

\bar is an accent: a fixed-width bar centred over one character, like \hat and \tilde. Over two letters it stays short and looks wrong. \overline draws a rule as wide as its argument, so it is the right choice for segments (\overline{AB}), conjugates of expressions and repeating decimals.

Over a single letter \overline{x} is a little wider and higher than \bar{x}. Pick one style for the whole document.

If you meant the vertical bar

For |x| type |x| or, better for spacing, \lvert x \rvert. For "such that" and "divides" use \mid. For a norm use the double bar \lVert x \rVert.

Common mistakes

  • \bar does not stretch; over two letters it covers only the middle.

    Instead of
    \bar{AB}
    Write
    \overline{AB}
  • Braces make the bar sit on x only and the subscript go after it.

    Instead of
    \bar x_1
    Write
    \bar{x}_1
  • \= is the text-mode macron accent; in math mode use \bar.

    Instead of
    \={x}  (in math)
    Write
    \bar{x}

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    \bar, \overline and \underline need no packages.

  • MathJax and KaTeX

    MathJax and KaTeX support \bar, \overline, \vert and \mid. \widebar (from some font packages) is not available.

  • Microsoft Word

    In a Word equation type x\bar then Space for x̄, or use Accent › Bar. In normal text, type x and then the combining macron (0304, then Alt+X on Windows).

Have this math on paper, in a PDF or a photo?

Retyping formulas is slow. These converters read whole pages and handwriting and give you LaTeX or Word with every equation editable.

Single printed formulas are free: 3 a day without an account, 6 with a free account. New accounts get 30 credits to try handwriting, pages and documents; failed conversions return their credits. See plans and credit prices.

Bar (x̄) and overline in LaTeX: questions

How do I write x bar in LaTeX?
\bar{x}.
How do I put a line over several letters?
Use \overline{AB}; it stretches over the whole group.
How do I write a vertical bar?
| or \vert; use \mid for "such that" and "divides".

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