Absolute Value in LaTeX

For a simple absolute value type the bars: |x|. amsmath’s \lvert x \rvert is the cleaner form because LaTeX then knows which bar opens and which closes. For tall contents use \left| \frac{a}{b} \right|, and write a norm with double bars: \lVert v \rVert.

Absolute value and norm

  • |x|
    | x |

    Quickest form; fine for simple cases.

  • \lvert x \rvert
    | x |

    Opening and closing bars with correct spacing (amsmath).

  • \left| \frac{a}{b} \right|
    | a b |

    Bars that grow with the contents.

  • \bigl| x \bigr|
    | x |

    One size larger, chosen by hand (also \Bigl, \biggl).

  • \lVert v \rVert
    ‖ v ‖

    Norm with double bars (amsmath).

  • \|v\|
    ∥ v ∥

    Short form of the double bars.

  • \left\lVert \mathbf{v} \right\rVert_2
    ‖ v ‖ 2

    Stretching norm with a subscript.

  • \abs{x}
    Text mode, no math preview

    Your own macro after \DeclarePairedDelimiter\abs{\lvert}{\rvert} (mathtools).

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

Absolute value 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.

  • Definition

    | x | = { x x ≥ 0 − x x < 0
    LaTeX
    |x| = \begin{cases} x & x \ge 0 \\ -x & x < 0 \end{cases}
  • Triangle inequality

    | a + b | ≤ | a | + | b |
    LaTeX
    \lvert a + b \rvert \le \lvert a \rvert + \lvert b \rvert
  • Absolute value of a fraction

    | x − μ σ | < 2
    LaTeX
    \left| \frac{x - \mu}{\sigma} \right| < 2
  • Complex modulus

    | z | = a 2 + b 2
    LaTeX
    \lvert z \rvert = \sqrt{a^2 + b^2}
  • Euclidean norm

    ‖ x ‖ 2 = ∑ i = 1 n x i 2
    LaTeX
    \lVert \mathbf{x} \rVert_2 = \sqrt{\sum_{i=1}^{n} x_i^2}
  • Hand-sized bars

    | ∑ i a i | ≤ ∑ i | a i |
    LaTeX
    \Bigl| \sum_{i} a_i \Bigr| \le \sum_{i} |a_i|

    \Bigl and \Bigr pick a fixed size; handy when \left … \right makes the bars too tall.

  • Determinant bars

    det A = | A |
    LaTeX
    \det A = \lvert A \rvert

Why \lvert and \rvert instead of |

The keyboard | is one symbol for both sides, so in expressions like |-x| LaTeX may space the minus sign as a binary operator. \lvert and \rvert (from amsmath) mark the opening and closing bar, which fixes the spacing.

Neither form grows by itself. \left| … \right| stretches the bars to the height of the contents; the fixed sizes \bigl|, \Bigl|, \biggl| give you control when automatic sizing looks too large.

An \abs macro with mathtools

In Overleaf you can define paired delimiters once and reuse them. \abs{x} gives normal bars, \abs*{…} makes them stretch, and \abs[\big]{…} picks a size. The same works for norms.

LaTeX
\usepackage{mathtools}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}
\DeclarePairedDelimiter\norm{\lVert}{\rVert}
% ...
\[ \abs*{\frac{a}{b}} \le \norm{x} \]

Common mistakes

  • Plain bars stay one line tall and look too short next to a fraction.

    Instead of
    |\frac{a}{b}|
    Write
    \left| \frac{a}{b} \right|
  • Two single bars are spaced apart; \lVert … \rVert (or \|v\|) draws a proper double bar.

    Instead of
    ||v||
    Write
    \lVert v \rVert
  • Every \left needs a matching \right with a delimiter; use \right. for an invisible one.

    Instead of
    \left| x \right  (missing the second bar)
    Write
    \left| x \right|

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    |x|, \left| \right| and \| work anywhere. \lvert, \rvert, \lVert, \rVert and \bigl need amsmath; \DeclarePairedDelimiter needs mathtools.

  • MathJax and KaTeX

    MathJax and KaTeX support \lvert, \rvert, \lVert, \rVert, \left| \right| and the \big sizes. In Markdown tables a bare | can split the table cell, so \lvert … \rvert is also the safer choice there.

  • Microsoft Word

    Word has bracket templates for bars, but pasted LaTeX is not converted reliably. Write the expression here and use Copy for Word to paste an editable equation.

Absolute value in LaTeX: questions

How do I write absolute value in LaTeX?
Use |x| for simple cases or \lvert x \rvert with amsmath. For fractions and other tall contents use \left| … \right|.
How do I make absolute value bars bigger?
Let them grow with \left| … \right|, or pick a size with \bigl| … \bigr|, \Bigl| … \Bigr| or \biggl| … \biggr|.
How do I write a norm with double bars?
Use \lVert x \rVert (amsmath) or \|x\|. Add a subscript after the closing bar for the kind of norm: \lVert x \rVert_2.
Why does my absolute value break a Markdown table?
Markdown uses | to separate table cells. Write the bars as \lvert and \rvert inside tables.

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