mathtools
mathtools copied to clipboard
[Feature proposal] Variable width underbrace
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}
Or accepting some trim arguments, like \cmidrule
from booktabs
package.