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}Short bar over one character.
\overline{AB}Bar over the whole group; grows with the content.
\underline{x}The same line below.
\bar{\bar{x}}Double bar (grand mean).
\vert x \vertVertical bars for absolute value;
|x|is the same.\{ x \mid x > 0 \}\midis 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.
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.
Sample mean
LaTeX\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_iLine segment
LaTeX\overline{AB} \parallel \overline{CD}Complex conjugate
LaTeXz\,\bar{z} = \lvert z \rvert^2Conjugate of a sum
LaTeX\overline{z_1 + z_2} = \overline{z_1} + \overline{z_2}Closure of a set
LaTeX\overline{\mathbb{Q}} = \mathbb{R}Repeating decimal
LaTeX0.\overline{3} = \tfrac{1}{3}
\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
\bardoes 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_1Write\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,\overlineand\underlineneed no packages.MathJax and KaTeX
MathJax and KaTeX support
\bar,\overline,\vertand\mid.\widebar(from some font packages) is not available.Microsoft Word
In a Word equation type
x\barthen 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.
- Handwritten math to LaTeXPhotograph notes or a whiteboard and get LaTeX for every line.1 credit per image
- PDF to LaTeXTurn a paper or textbook PDF into a .tex project with every equation.10 credits per page
- Image to WordA screenshot or photo of a page becomes Word with editable equations.10 credits per image
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\midfor "such that" and "divides".
Related LaTeX reference
- Hat in LaTeX\hat and \widehat accents, hats with subscripts, dotless i and j, and how to print the ^ character itself.
- Tilde (~) in LaTeXWhy ~ prints a space, how to get a visible tilde in text, the \tilde and \widetilde accents, and \sim in math.
- LaTeX Underline: Text and Math\underline for short text and formulas, ulem's \uline and soul's \ul for text that breaks across lines, plus double and wavy lines.
- Accents in LaTeXText accents (é ü ñ ç å) with \' \" \~ \c \r, math accents (\hat \bar \tilde \dot \vec) and when to just type UTF-8.
- Congruent Symbol in LaTeX≅ with \cong for geometry and isomorphism, ≡ with \equiv and \pmod for modular arithmetic, and \ncong / \not\equiv.
- How to Write an Ampersand in LaTeXPrint & with \&; & on its own is the column separator in tables, matrices and aligned equations.
- 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