# Adding left/right bars to letters

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.

-
Welcome to TeX.sx! Can you point to some place where this notation is used or make some examples? –  egreg Nov 29 '12 at 8:38
Do you mean something like $|a|$? –  Peter Grill Nov 29 '12 at 9:07
Which would be wrong in some cases $\lvert -a \rvert \neq |-a|$. –  daleif Nov 29 '12 at 9:58

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:

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

-
The place where you say \right| is handy is not the best illustration; in that case one should prefer \;\middle|\; (removing the \left.), but this is still a different usage of the bar, because it's a relation symbol. –  egreg Dec 27 '12 at 11:38
To my understanding the solution with \lvert/\rvert is not the same as witha \left|/\right| because the \levert and \rvert delimiters may have special positions for sub/superscripts. –  Marc van Dongen Dec 27 '12 at 11:40
@egreg Thanks for the heads up, I always used it, like I wrote, but your solution seems way better than mine. –  xfoo Dec 27 '12 at 12:25