7

Everyone seems to ask about this and the usual solution seems to be to use \lvert and \rvert with the amsmath package, but that doesn't work for me either.

example:

f_{3,2} = \left(\sqrt{13}-2-\lvert \frac{\sqrt{13}}{6}+2-2\sqrt{7}\left(1+\delta V\right)\rvert\right)/4  

Here's what I get

enter image description here

I want the absolute value bars to scale taller in accordance with the content.

What am I doing wrong?

Steve
  • 275

1 Answers1

13

You can scale then with \left\lvert and \right\rvert, just as with parentheses.

f_{3,2} = \left(\sqrt{13} - 2 - \left\lvert \frac{\sqrt{13}}{6} + 2
- 2\sqrt{7}\left(1 + \delta V\right) \right\rvert \right)/4  

If you load the mathtools package, you can use a \DeclarePairedDelimiter command which simplifies scaling delimiters: writing \DeclarePairedDelimiter{\abs}{\lvert}{\rvert} defines two commands: \abs, which delimits its argument with \lvert and \rvert, and \abs*, which does the same, but scaling it automatically.

Here's what this would look like for your code.

% in preamble
\usepackage{mathtools}
\DeclarePairedDelimiter{\paren}{(}{)}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

% document
f_{3,2} = \paren*{\sqrt{13} - 2 - \abs*{\frac{\sqrt{13}}{6} + 2
- 2\sqrt{7}\paren*{1 + \delta V}}}/4  
Arun Debray
  • 7,126
  • 2
  • 30
  • 54
  • 2
    Even better use mathtools and it's \DeclarePairedDelimiter to make \abs{} (i think it is even an example in the manual). It gives you a simpler interface to use. – daleif Nov 11 '15 at 19:36
  • 1
    My god. Thank you Arun. But why god does LaTeX need "\left" and "\lvert" (with an "l" for left!)? Makes no sense. Either way, this has been causing me problems forever, so thanks! – Steve Nov 11 '15 at 19:38
  • 1
    @daleif: oops, while you wrote that I was editing in an answer to use that. Thanks for pointing it out, though! – Arun Debray Nov 11 '15 at 19:39
  • @Steve: the l and r in \lvert and \rvert indicate "spacing as a left delimiter" and "spacing as a right delimiter," respectively. I agree it's counterintuitive, but there are times where I want the correct spacing, but to not scale the delimiters, such as $\abs{A_j}$ in text mode (if the delimiters scaled with the subscript, it would make the line too tall). So it's nice to have both options. – Arun Debray Nov 11 '15 at 19:43
  • Thanks for explaining that, that actually makes sense! I was thinking \lvert and \rvert would be essentially identical since the symbol itself is horizontally symmetric, but I'm guessing this means that the two symbols are actually different in the amount of blank space on the left and right sides of the symbol--which makes sense. – Steve Nov 11 '15 at 19:48
  • You might want to add an example using manual scaling, the abs of a sum is usually a good example – daleif Nov 11 '15 at 19:50
  • 3
    @Steve try |-1| vs \lvert -1\rvert then you will see the significance – daleif Nov 11 '15 at 19:58