Absolute value and norm in LaTeX (lvert, lVert)

Write an absolute value as \lvert x \rvert and a norm as \lVert v \rVert; both pairs come from amsmath. The plain forms |x| and \|v\| print the same bars but can get the spacing wrong.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{mathtools}

Absolute value and norm

\lvert and \lVert open, \rvert and \rVert close. A subscript after the closing bar names the norm.

\[
  \lvert x \rvert
  \qquad
  \lvert a - b \rvert
  \qquad
  \lVert v \rVert
  \qquad
  \lVert x \rVert_2
\]
Change the formula

The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.

∣x∣∣a−b∣∥v∥∥x∥2\lvert x \rvert \qquad \lvert a - b \rvert \qquad \lVert v \rVert \qquad \lVert x \rVert_2

Open this formula in the editor

Why not the plain bar

The | key does not tell LaTeX whether a bar opens or closes. In |-x| the minus is therefore spaced as a subtraction between two terms. \lvert -x \rvert sets it close to the x, as a sign.

Wrong spacing: $|-x|$, correct: $\lvert -x \rvert$.
Result
The compiled example

Open in the editor

Bars that grow with the content

\left and \right in front of the bars scale them to the content. \bigl and \bigr set a fixed larger size.

\[
  \left\lvert \frac{a}{b} \right\rvert
  \qquad
  \left\lVert \sum_{i} v_i \right\rVert
  \qquad
  \bigl\lvert x - y \bigr\rvert
\]
Change the formula

The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.

∣ab∣∥∑ivi∥∣x−y∣\left\lvert \frac{a}{b} \right\rvert \qquad \left\lVert \sum_{i} v_i \right\rVert \qquad \bigl\lvert x - y \bigr\rvert

Open this formula in the editor

Define abs and norm commands

\DeclarePairedDelimiter from mathtools defines \abs{x} and \norm{v}. The starred form \abs*{...} scales the bars with \left and \right, and an optional argument such as [\big] sets a fixed size.

Complete document:

\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\begin{document}
\[
  \abs{x}
  \qquad
  \abs*{\frac{a}{b}}
  \qquad
  \norm{v}_2
  \qquad
  \norm[\big]{x - y}
\]
\end{document}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages