6

This refers to the following sophisticated solution by @David Carlisle for applying \underbrace to multiline expressions:

  1. How can I still use \underbrace on a single-line expression? All I get from the common use of \underbrace with the proposed solution is

enter image description here

  1. How can I get the brace under an expression that spans only two lines with the tip of the brace below the second line's part of the brace? All I get is

enter image description here

  1. What is the most flexible approach to multiline '\underbrace' apart from obviously avoiding such notation when possible?

Here is (for convenience) David Carlisle's code with the problematic equations added:

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\def\underbracex#1#2{\mathop{\vtop{\m@th\ialign{##\crcr
   $\hfil\displaystyle{#2}\hfil$\crcr
   \noalign{\kern3\p@\nointerlineskip}%
   #1\crcr\noalign{\kern3\p@}}}}\limits}

\def\underbracea{\underbracex\upbracefilla}

\def\upbracefilla{$\m@th \setbox\z@\hbox{$\braceld$}%
  \bracelu\leaders\vrule \@height\ht\z@ \@depth\z@\hfill 
\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@
$}

\def\underbraceb{\underbracex\upbracefillb}

\def\upbracefillb{$\m@th \setbox\z@\hbox{$\braceld$}%
\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@
 \leaders\vrule \@height\ht\z@ \@depth\z@\hfill\bracerd
  \braceld\leaders\vrule \@height\ht\z@ \@depth\z@\hfill
\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@
$}


\def\underbracec{\underbracex\upbracefillc}

\def\upbracefillc{$\m@th \setbox\z@\hbox{$\braceld$}%
\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@
\leaders\vrule \@height\ht\z@ \@depth\z@\hfill
\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@
$}

\def\underbraced{\underbracex\upbracefill}
\def\upbracefill{$\m@th \setbox\z@\hbox{$\braceld$}%
\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@
 \leaders\vrule \@height\ht\z@ \@depth\z@\hfill\braceru$}


\makeatother
\begin{document}

    \begin{align}
        \underbrace{a+b}_{=c} \\
        \underbracea{d + e} \\
        \underbraced{f+g}_{=h}
    \end{align}

\begin{align*}
 A ={}& B + \underbracea{C + D + E} \\
      &\underbraceb{{} + F + G}_{=:M} \\
      &\underbracec{{}+ H + I} \\
      &\underbraced{{} + J + K} + L
\end{align*}

\end{document}

1 Answer 1

10

enter image description here

There is an error in the old answer: the last clause was supposed to be variant d but it was written with no final letter so redefined the standard \upbrace macro to only make half a brace which was not the intention. Fixed below.

here I add one more variant bd that is a combination of b that had the "spike" and d which is the extending right half of a brace.

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\def\underbracex#1#2{\mathop{\vtop{\m@th\ialign{##\crcr
   $\hfil\displaystyle{#2}\hfil$\crcr
   \noalign{\kern3\p@\nointerlineskip}%
   #1\crcr\noalign{\kern3\p@}}}}\limits}

\def\underbracea{\underbracex\upbracefilla}

\def\upbracefilla{$\m@th \setbox\z@\hbox{$\braceld$}%
  \bracelu\leaders\vrule \@height\ht\z@ \@depth\z@\hfill 
\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@
$}

\def\underbraceb{\underbracex\upbracefillb}

\def\upbracefillb{$\m@th \setbox\z@\hbox{$\braceld$}%
\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@
 \leaders\vrule \@height\ht\z@ \@depth\z@\hfill\bracerd
  \braceld\leaders\vrule \@height\ht\z@ \@depth\z@\hfill
\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@
$}


\def\underbracec{\underbracex\upbracefillc}

\def\upbracefillc{$\m@th \setbox\z@\hbox{$\braceld$}%
\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@
\leaders\vrule \@height\ht\z@ \@depth\z@\hfill
\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@
$}

\def\underbraced{\underbracex\upbracefilld}
\def\upbracefilld{$\m@th \setbox\z@\hbox{$\braceld$}%
\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@
 \leaders\vrule \@height\ht\z@ \@depth\z@\hfill\braceru$}

\def\underbracebd{\underbracex\upbracefillbd}
\def\upbracefillbd{$\m@th \setbox\z@\hbox{$\braceld$}%
\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@\vrule \@width\p@\kern\p@
\bracerd\braceld
 \leaders\vrule \@height\ht\z@ \@depth\z@\hfill\braceru$}


\makeatother
\begin{document}

    \begin{align}
        \underbrace{a+b}_{=c} \\
        \underbracea{d + e} \\
        \underbracebd{f+g}_{=h}
    \end{align}

\begin{align*}
 A ={}& B + \underbracea{C + D + E} \\
      &\underbraceb{{} + F + G}_{=:M} \\
      &\underbracec{{}+ H + I} \\
      &\underbraced{{} + J + K} + L
\end{align*}

\end{document}
3
  • This solution is great, but there is an issue, if the package mathabx is loaded. Only \underbracec continues to work, the other versions have the dots vertically stretched. Is there any fix?
    – Elarion
    Commented Jul 8, 2020 at 9:15
  • Mathx of mathabx redefines underbrace and its components, hence when loading mathx the issue shows up
    – Elarion
    Commented Jul 8, 2020 at 9:59
  • Could you give an explanation on how this magic works? I'd like to add underbraceab as well as braket / parentheses and overbrace versions. But I am apparently a TeX-illiterate.
    – BadAtLaTeX
    Commented Sep 2, 2023 at 17:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .