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.
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$.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.
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}Pitfalls
- The
physicspackage already defines\absand\norm. Declaring them again stops with Command \vec already defined. ||v||prints two single bars with a gap between them. The double bar is one character:\|or\lVert.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
mathtools - Package
amsmath - Package
physics - How-to Large brackets in LaTeX
- Error Command \vec already defined