0

I am having trouble getting the correct scaling of my absolute value brackets.

The MWE looks like this

\newcommand{\abs}[1]{\left| #1 \right|}
\begin{align*}
 &\abs{x y} \cr
 \abs{&x y} \cr
 \abs{&x \cr &y}
\end{align*}

The output produced gives me correct brackets in the first case |xy| but all other cases only show the first (correctly scaled) bracket but not the second one, i.e. |xy .

What would be the correct way to go about this?

  • You can't put an alignment tab in the middle of a macro argument, especially one that is its own group – Steven B. Segletes Sep 11 '17 at 15:22
  • You cannot, left... Right constructions form a group effectively hiding the & from align. Your best option is to manually scale (bedt options anyway, IMO). Btw: welcome – daleif Sep 11 '17 at 15:23

1 Answers1

1

With the \DeclarePairedDelimiterand \MTkillspecial from mathtools, you can. The \ abs command defined in this code adds a pair of implicit \left \right in front of the delimiters if you use the starred version. Alternatively, you can fine-tune the size pf the vertical rules with the optional argument: \abs[\big], \abs[\Big], &c.:

\documentclass{article}
\usepackage{mathtools, xparse}

\usepackage{xcolor}

\newcommand\MTkillspecial[1]{% helper macro
\bgroup
\catcode`\&=9
\let\\\relax%
\scantokens{#1}%
\egroup
}

\DeclarePairedDelimiter\abs\lvert\rvert
\reDeclarePairedDelimiterInnerWrapper\abs{star}{
\mathopen{#1\vphantom{\MTkillspecial{#2}}\kern-\nulldelimiterspace\right.}
#2
\mathclose{\left.\kern-\nulldelimiterspace\vphantom{\MTkillspecial{#2}}#3}}


\begin{document}

\begin{align*}
         & \color{red}\abs*{\color{black}x y} \\
  \abs*{ & \color{red}x\color{black} y} \\
  \abs*{ & \color{red}x \\ &\color{red}y\color{black} }
\end{align*}

\end{document} 

enter image description here

Bernard
  • 271,350