mathtools icon indicating copy to clipboard operation
mathtools copied to clipboard

[Feature proposal] Variable width underbrace

Open cspiel opened this issue 2 years ago • 1 comments

I used \underbrace on a matrix and found that the generous white space at both sides of the matrix results in a brace too wide. Therefore, I extended the original code to arrive at \scaledunderbrace, which allows to scale the relative width of the brace with the help of an optional argument.

The implementation is naive, but variable-width under- (or over-) thingies could be interesting for other users, too.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{mathtools}

\makeatletter
\newcommand*{\scaledunderbrace}[2][1.0]
            {\setbox0=\hbox{$\m@th\displaystyle{#2}$}%
             \dimen0=\wd0
             \dimen1=-#1\dimen0
             \advance\dimen1 by\dimen0
             \mathop{\vtop{\m@th\ialign{##\crcr
                     $\hfil\box0\hfil$\crcr
                     \noalign{\kern.7\fontdimen5\textfont2\nointerlineskip}%
                     \kern.5\dimen1\hbox to #1\dimen0{\upbracefill}\crcr
                     \noalign{\kern.5\fontdimen5\textfont2}}}}\limits}
\makeatother

\begin{document}
Default \texttt{\string\underbrace} (from package \textsf{mathtools})
\begin{equation*}
  \underbrace{\begin{pmatrix}0 & I \\ -I & 0\end{pmatrix}}_{\Sigma :=}
\end{equation*}

New \texttt{\string\scaledunderbrace}
\begin{align*}
  \scaledunderbrace[.667]{\begin{pmatrix}0 & I \\ -I & 0\end{pmatrix}}_{\Sigma :=}  &&
  \scaledunderbrace{\begin{pmatrix}0 & I \\ -I & 0\end{pmatrix}}_{\Sigma :=}  &&
  \scaledunderbrace[1.1]{\begin{pmatrix}0 & I \\ -I & 0\end{pmatrix}}_{\Sigma :=}
\end{align*}
\end{document}

Comparison of default implementation and \scaledunderbrace with three different relative widths scaledunderbrace

cspiel avatar Nov 28 '22 08:11 cspiel

Or accepting some trim arguments, like \cmidrule from booktabs package.

muzimuzhi avatar Nov 29 '22 22:11 muzimuzhi