Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature proposal] Variable width underbrace #50

Open
cspiel opened this issue Nov 28, 2022 · 1 comment
Open

[Feature proposal] Variable width underbrace #50

cspiel opened this issue Nov 28, 2022 · 1 comment

Comments

@cspiel
Copy link

cspiel commented Nov 28, 2022

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

@muzimuzhi
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants