Skip to content

[Feature proposal] Variable width underbrace #50

Description

@cspiel

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions