8

I would like to typeset the absolute value of a fraction, e. g.

with absolute value bars that are shorter at the bottom, like in

Is there any way in LaTeX to achieve this rather than the first example?

Details:

I am calculating the angle between two lines in three-dimensional space with the following formula:

This looks really nice. But when I now substitute the coordinates of the vectors like this:

\cos\phi=\left|\frac{
        \begin{pmatrix}1\\1\\1\end{pmatrix}
    \circ
        \begin{pmatrix}1\\2\\3\end{pmatrix}
    }{
        \sqrt3\cdot\sqrt{1^2+2^2+3^2}
    }\right|

I get the following result:

Yuck! There is way too much space below the fraction inside the absoulte value bars!

I already tried using \Biggl| and \Biggr:

\cos\phi=\Biggl|\frac{
        \begin{pmatrix}1\\1\\1\end{pmatrix}
    \circ
        \begin{pmatrix}1\\2\\3\end{pmatrix}
    }{
        \sqrt3\cdot\sqrt{1^2+2^2+3^2}
    }\Biggr|

but that only yields a somewhat acceptable, but slightly incorrect result:

4
  • 1
    Related and probably adaptable: tex.stackexchange.com/q/472540/134144
    – leandriis
    Feb 23 at 19:15
  • 1
    Unrelated: what is the composition of two vectors?
    – Bernard
    Feb 23 at 19:17
  • In Bavarian (German?) schools, we use \circ as the symbol for the scalar product. I don't know why - we could as well use < . >, but for some reason we don't.
    – Iziminza
    Feb 24 at 13:42
  • @leandriis: That's really interesting - I already know I will come back for those funny asymmetric braces one day! But for something as simple as vertical bars I prefer Steven's answer below.
    – Iziminza
    Feb 24 at 14:07
8

Here, I use \stretchleftright{|}{...}{|} to achieve it.

\documentclass{article} 
\usepackage{scalerel,amsmath}
\begin{document} 
\[
\cos\phi=\stretchleftright{|}{\frac{
        \begin{pmatrix}1\\1\\1\end{pmatrix}
    \circ
        \begin{pmatrix}1\\2\\3\end{pmatrix}
    }{
        \sqrt3\cdot\sqrt{1^2+2^2+3^2}
    }}{|} 
\]
\end{document}

enter image description here

2
  • Well .. this is simply great, thanks! And I noticed that \stretchleftright works for ( [ \{ \} ] ) as well!
    – Iziminza
    Feb 24 at 13:51
  • 1
    @Iziminza Yes, it works for any glyph, but BEWARE, by stretching a [, the vertical line stays the same, but the horizontal lines thicken (ugh). The result is more presentable for parens than brackets. p.s. There is also a \scaleleftright to scale rather than stretch the delimiters. You should also look into their optional arguments, which can be of use, as well. Feb 24 at 15:38
7

I'd like to suggest a solution that's different from either of your preferred choices.

enter image description here

\documentclass{article}
\usepackage{mathtools} % for '\DeclarePairedDelimiter' macro
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\begin{document}
\[
\cos\phi= \frac{1}{\sqrt3 \cdot\sqrt{1^2+2^2+3^2}}
          \abs*{\begin{pmatrix}1\\1\\1\end{pmatrix}\circ
                \begin{pmatrix}1\\2\\3\end{pmatrix}}  
\]
\end{document}
1
  • Thanks! I could have also put the absolute value bars around the numerator alone. But our textbook puts the whole fraction inside them, so I prefer the other solution in order not to confuse my students.
    – Iziminza
    Feb 24 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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