Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
3  
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
1  
Which would be wrong in some cases $\lvert -a \rvert \neq |-a|$. –  daleif Nov 29 '12 at 9:58

1 Answer 1

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!

share|improve this answer
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.