Bar / overline (x̄) in LaTeX
The bar accent \bar{x} draws a short horizontal line over a single symbol, most often to denote a sample mean (x-bar) or a complex conjugate. For a bar that spans several symbols use \overline{...} instead.
LaTeX command
\bar{x}Not the symbol you meant? Draw it to find the command →
Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →
\bar{x} is a math-mode accent whose bar is sized for one character. It is the standard notation for the sample mean of a data set, and also appears for the complex conjugate of a number and for the complement of a set. It needs no extra package and renders in KaTeX anywhere in math mode.
The key distinction is width. \bar always produces a fixed, narrow bar tuned to a single letter, so \bar{AB} looks wrong because the line is too short. When the bar must cover two or more symbols, a whole expression, or a repeating decimal, switch to \overline{...}, which stretches to fit its contents.
Both commands are purely visual and do not change how the symbol behaves in an equation. Use \bar for one letter and \overline for a group, closure or conjugate of an expression such as \overline{z_1 z_2}. For a line underneath use \underline instead.
Other forms
\overline{x+y}overline over several symbolsExamples
$\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i$the sample mean
$\overline{z} = a - bi$complex conjugate over a single symbol
$\overline{z_1 + z_2} = \overline{z_1} + \overline{z_2}$\overline stretches over an expression
$\overline{A \cup B} = \bar{A} \cap \bar{B}$De Morgan with set complements
$0.\overline{3} = \frac{1}{3}$a repeating decimal
Tips and common mistakes
- Use
\bar{x}for one symbol; the moment the bar must cover more than one character, switch to\overline{...}or it will be too short. - Neither
\barnor\overlineneeds a package; both are core LaTeX and are supported by KaTeX. - Mind subscripts:
\bar{x}_ibars the x then adds the index, whereas\overline{x_i}draws the bar over the whole x_i. - For a wide bar over an arc or segment use
\overline; for a directed segment use\overrightarrowinstead. - Do not confuse
\barwith\hator\tilde; each is a different accent but all share the same single-character sizing.
Working from handwritten notes?
LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.
See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).
Convert your maths to LaTeX →FAQ
What is the LaTeX command for x bar (the mean)?
Write in math mode. It renders a short bar over the x, the standard symbol for a sample mean.
How do I put a bar over more than one letter?
Use \overline{...}, for example or . \bar only sizes itself to one character and will look too short over a group.
What is the difference between \bar and \overline?
\bar is a fixed-width accent for a single symbol; \overline stretches to cover whatever is inside its braces. Neither needs an extra package.