[Tex/LaTex] Adding left/right bars to letters

graphicsmath-modesymbolstext-decorations

Is there an equivalent of the top/bottom bars you can get with \overbar, \underbar but for left and right bars? I would like to have a small vertical bar right next to some text in mathmode.

I would prefer existing solutions in some package but a custom macro/command is also fine.

Best Answer

Even though your question might have been answered already in the comments, here an example how one could use absolute values or at least the | symbol.

\documentclass{article}
% Should be in every document, if you write math 
\usepackage{amsmath,amssymb}

\begin{document}
\[
|a+b| \leq \left| a \right| + \lvert b \rvert 
\]

\[
\left\{ n \in \mathbb{N} \;\middle|\; \sum_{k=0}^n \binom nk \right\}
=
\left\{ 2^n \;\middle|\; \forall n \in \mathbb{N} \right\}
\]

\[
|x| =
\begin{cases}
x  &\mathrm{if}\ x \geq 0\\
-x &\mathrm{if}\ x  <  0
\end{cases}
\]
\end{document}

As daleif pointed out, they might not be the same, but I think as long as you choose one and stick with it, it shouldn't be a problem. I recommend using \left|, \middle| and \right|, because LaTeX will automaticly adjust the height of |, the prefixes will also work with brackets, as you can see in my second example.

So here the output:

Output of the example

For future works, you may find this site handy. Have Fun!

Related Question