When we create mathematical expressions or formulas using LaTeX, we need different symbols. Among these, the vertical bar is a common symbol, which you will learn to use in this tutorial.
There are various commands for using the symbol, such as |
, \mid
, \vert
, etc. Each command has its own use and relevance. Below, we discuss with examples which command to use in which situation.
\documentclass{article}
\begin{document}
\[a|b\]
\[a\vert b\]
\[a\mid b\]
\end{document}
Output :
The above three are math mode commands used in ред
and \vert
for both text and equations and they don’t need any spaces on either side.
The \mid
command should be used when you want to indicate conditions or division, and it automatically adds a small space on both sides, which |
or \vert
commands do not.
Using different sizes of vertical bars
At times, you may need to use vertical bars of different sizes. In LaTeX, you can use commands like \big|
, \Big|
, \bigg|
, and \Bigg|
to set the size of the delimiters. For example:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[a \big| b \quad a \Big| b \quad a \bigg| b \quad a \Bigg| b\]
\[\cfrac{1}{x}\,\Bigg|_{a}^{b}\]
\end{document}
Output :
If you want to use the \mid command to indicate conditions or divisions within a set and show them in different sizes, you can use the commands \bigm|
, \Bigm|
, \biggm|
, and \Biggm|
. These commands work like \mid but are larger in size.
\documentclass{article}
\usepackage{amsmath,amsfonts}
\begin{document}
\[ a \bigm| b \qquad a \Bigm| b \qquad a \biggm| b \qquad a \Biggm| b \]
\[ \left\{ x \in \mathbb{R} \Biggm| x^2 \leq 4 \right\} \]
\end{document}
Output :
Using \left. and \right|
With the \left.
and \right|
commands, you can add a vertical bar that automatically adjusts to the height of expression.
Here, \left.
is an invisible delimiter. It is used when you want a matching delimiter on the right side but do not want anything to appear on the left side.
Using \left.
, you indicate to LaTeX that a delimiter starts here, but it is not visible.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[\left. \int_0^x t^2 \, dt \right|_{x=1} \]
\[\left. \cfrac{dy}{dx} \right|_{x=0} \]
\end{document}
Output :
In this example, \left.
creates an empty space on the left side of the expression without adding a visible bracket, and \right| adds a vertical bar that adjusts to the height of the expression.
Double vertical bar symbol
In LaTeX, to create a double vertical bar symbol, you can use the \|
or \Vert
commands. But, \Vert
is a bit more formal and used in specific situations.
\documentclass{article}
\begin{document}
\[a \| b\]
\[a \Vert b\]
\end{document}