Drawing absolute value bars around a fraction with different height of numerator and denominator

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:

• Related and probably adaptable: tex.stackexchange.com/q/472540/134144 Feb 23 at 19:15
• Unrelated: what is the composition of two vectors? 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. 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. Feb 24 at 14:07

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}


• Well .. this is simply great, thanks! And I noticed that \stretchleftright works for ( [ \{ \} ] ) as well! Feb 24 at 13:51
• @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

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

\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}

• 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. Feb 24 at 13:53