[Tex/LaTex] Angle brackets with an underset arrow

arrowsboxesbracketsmath-mode

I am trying to make a pair of angle brackets of variable height enclosing a main box along with a box beneath each bracket and an arrow of variable length between these lower boxes. Since I'm sure that's extremely unclear, here are two hand-drawn (and a little crooked) examples of what I mean:

With my limited skills, here is the code I managed to produce:

\newcommand{\imfun}[3]{\underset{#1 \;-\hspace{-.1in} \hfill \rightarrow \; #3}{\sbox0{$#2$}
\mathopen{\resizebox{1.2\width}{\ht0}{$\Bigg\langle$}}
\usebox{0}
\mathclose{\resizebox{1.2\width}{\ht0}{$\Bigg\rangle$}}
}}

The three arguments are the three content boxes: lower left, main, and lower right. In this implementation, the angle brackets do not change height gracefully and no attempt has been made to connect the head of the arrow to the tail.

I certainly appreciate any help you can offer!

Best Answer

The following example centers the left and right annotation text below the delimiters and puts an extensible arrow between. The example uses package amsmath and defines the following environments:

  • Environment amatrix sets a matrix with angle brackets as delimiters, similar to environments bmatrix, pmatrix of package amsmath.
  • Environment amatrixarrow takes one optional and two mandatory arguments and sets the annotations below the matrix connected by an arrow.

    \begin{amatrixarrow}[0.25ex]{left}{right} ... \end{amatrixarrow}
    

    The optional argument specifies the distance between matrix and annotation. The default is 0.5ex of the annotation's font size and can be overwritten by the optional argument.

Example file:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newenvironment{amatrix}{%
  \left\langle
  \env@matrix
}{%
  \endmatrix
  \right\rangle
}

\newcommand{\amatrixarrow}[3][.5ex]{%
  \def\amatrixarrow@shift{#1}%
  \def\amatrixarrow@left{#2}%
  \def\amatrixarrow@right{#3}%
  \collect@body\amatrixarrow@next
}
\newcommand*{\amatrixarrow@next}[1]{%
  \mathpalette{\amatrixarrow@}{#1}%
}
\newcommand*{\amatrixarrow@}[2]{%
  % #1: math style (\displaystyle, \textstyle, ...)
  % #2: environment body
  \sbox0{$\m@th#1\begin{amatrix}#2\end{amatrix}$}%
  \sbox2{$\m@th#1\begin{matrix}#2\end{matrix}$}%
  \sbox4{$\m@th
    \amatrixarrow@style{#1}%
    \amatrixarrow@left
  $}%
  \sbox6{$\m@th
    \amatrixarrow@style{#1}%
    \amatrixarrow@right
  $}%
  \sbox8{$\m@th\amatrixarrow@style{#1}\text{\kern\amatrixarrow@shift}$}%
  \dimen0=.5\dimexpr\wd0-\wd2\relax
  \vtop{%
    \hbox{%
      \kern.5\dimexpr\wd4-\dimen0\relax
      % \fboxsep=0pt\fboxrule=.1pt \fbox{\copy0 }%
      \copy0 %
    }%
    \kern\wd8 %
    \nointerlineskip
    \hbox to \dimexpr\wd0+.5\wd4+.5\wd6-\dimen0\relax{%
      \copy4 %
      \hfill
      \sbox2{$\m@th
        \amatrixarrow@style{#1}%
        {}\xrightarrow{}{}%
      $}% shortest arrow with spacing
      $\m@th
        \amatrixarrow@style{#1}%
        \xrightarrow{%
          \kern\dimexpr\wd0-.5\wd4-.5\wd6-\dimen0-\wd2\relax
        }%
      $%
      \hfill
      \copy6 %
    }%
  }%
}
\newcommand*{\amatrixarrow@style}[1]{%
  \ifx#1\displaystyle
    \scriptstyle
  \else\ifx#1\textstyle
    \scriptstyle
  \else
    \scriptscriptstyle
  \fi\fi
  % #1%
}
%\renewcommand*{\amatrixarrow@style}[1]{#1}
\makeatother

\begin{document}
\[
  {\begin{amatrixarrow}[0ex]{2\oplus 1\oplus 1}{4\oplus 2\oplus 4}
    bc - ad & bb - aa & ca + bd \\
    0       & b - a   & 0       \\
    0       & 2a      & 0
  \end{amatrixarrow}}
\Rightarrow
  {\begin{amatrixarrow}{3}{3\oplus 3}
    abc - acb & abc - bac
  \end{amatrixarrow}}
\]
\end{document}

Result

Variant without decreased font size for annotation

I think the annotation looks better in a smaller math style. But it is possible to keep the current math style by changing the definition of \amatrixarrow@style to:

\newcommand*{\amatrixarrow@style}[1]{#1}

Result

Remarks (for the more experienced):

  • The environment amatrixarrow catches its body by amsmath's \collect@body. Then the environment contents can be used twice, in a matrix without delimiters and in amatrix with angle brackets. The horizontal position for the annotations are calculated by comparing the widths of the two matrices.

  • By using \vtop with the matrix as first element, the reference point of the matrix remains unchanged. The annotations just enlarge the depth of the whole construct.

  • \mathpalette provides the current math style.
  • The reason for the optional parameter is, that it is not known, how many white space the matrix contains at the bottom. Internally the matrix is implemented using environment array that automatically adds invisible struts. The depth of the strut in the bottom line might increase the optical distance between the annotations and the bottom of the matrix, as seen in the first matrix of the example.

  • In the example the environment amatrixarrow is put in curly braces to protect it from the parent environment align*.

  • The arrow is drawn via \xrightarrow with the spacing of the arrow as relational symbol.

Related Question