3

I currently use a macro:

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

in order to write absolute values, but I'm finding that when I combine this with \hat then the height is modified in an undesirable way:

\lvert \hat{x} \rvert, \quad \left\lvert \hat{x} \right\rvert, \quad \lvert \hat{\psi} \rvert, \quad \left\lvert \hat{\psi} \right\rvert  

The first three all have equal height on the absolute values, but the last is significantly higher. I can only presume this is something unique to the symbol \psi with \hat as opposed to a generic letter (in this case x). Is there any way around this without defining another macro (e.g. \normalabs without the \left and \right) or is there a better way to handle this?

MWE:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}

\[
\lvert \hat{x} \rvert, \quad \left\lvert \hat{x} \right\rvert, \quad \lvert \hat{\psi} \rvert, \quad \left\lvert \hat{\psi} \right\rvert    
\]

\end{document}

enter image description here

Werner
  • 603,163
Riley
  • 145
  • Why use the \left... and \right...? How about the same as the others...simply \lvert and \rvert? – Steven B. Segletes Dec 10 '20 at 00:36
  • I guess it's generally convenient, e.g. when working with summations and integrals to use \left and \right, otherwise the lines are too short. Should I define an \abs with a \bigabs which uses \left, \right? – Riley Dec 10 '20 at 00:42
  • 1
    You can use this answer. There is a religious disagreement on whether or not one should raise or lower delimiters, but at least for vertical bars it could be fine. –  Dec 10 '20 at 00:47

1 Answers1

2

You can update \abs to take an optional argument where you specify something different that will be used as the sizing-mechanism:

enter image description here

\documentclass{article}

\usepackage{xparse}% Not needed if you have an updated LaTeX as of Oct 2020. \usepackage{amsmath}

\NewDocumentCommand{\abs}{o m}{ \left\lvert \IfNoValueTF{#1} {#2}% No optional argument {\vphantom{#1}\smash{#2}}% Use optional argument for height purposes only \right\rvert }

\begin{document}

[ \abs{\hat{x}}, \quad \abs{\hat{x}}, \quad \lvert \hat{\psi} \rvert, \quad \abs{\hat{\psi}}, \quad \abs[\hat{x}]{\hat{\psi}} ]

\end{document}

Werner
  • 603,163