Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

\underbrace spanning multiple lines

1,809 views
Skip to first unread message

pech...@cs.technion.ac.il

unread,
Aug 10, 2005, 7:22:56 AM8/10/05
to
Is there any way to underbrace mathematical expression taking several
lines. I'd like to do something like
\begin{equation}
\begin{split}
A = & \underbrace{ B + \\
& C +}_{xxx} \\
& D
\end{split}
\end{equation}
but it does not pass Latex compilation.

Thanks in advance,
Dmitry Pechyony

Lars Madsen

unread,
Aug 10, 2005, 7:30:07 AM8/10/05
to

the above does of course not work because of the line breaks.

Here is a proof of concept showing that it could be done

\documentclass{article}
\usepackage{mathtools} % auto loads amsmath
\begin{document}
\begin{equation}
\begin{split}
a &= b +c +g +r_q \\
&\quad \underbrace{
\mathmakebox[\widthof{$\displaystyle b +c +g +r_q$}][l]{
+ x+y}}_{xxx}
\end{split}
\end{equation}
\end{document}

It not optimized at all, just showing that it can be done

--

/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ: http://www.tex.ac.uk/faq
Superb Class: http://www.ctan.org/tex-archive/help/Catalogue/entries/memoir.html
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal working examples.

pech...@cs.technion.ac.il

unread,
Aug 10, 2005, 8:00:32 AM8/10/05
to
Thanks for quick reply. Your code makes underbrace symbol under two
math lines. The underbrace symbol itself occupies single line. My
question is whether the single underbrace symbol may occupy several
lines.

Jean-Côme Charpentier

unread,
Aug 10, 2005, 8:34:38 AM8/10/05
to

I don't understand. One can define \underbraceleft, \underbraceright
(even \underbracemiddle) macros. But where put your _{xxx} (first
line, second one, split, other)?

Jean-Côme Charpentier

pech...@cs.technion.ac.il

unread,
Aug 10, 2005, 10:22:16 AM8/10/05
to
The placement of _{xxx} depends on the number of lines that underbrace
symbol should occupy, and in general it should be somewhere in the
middle.
If we have two lines, then _{xxx} should be at the end of the first
line (or at the start of the second line). If we have three lines then
_{xxx} should be in the middle of the second line.
How do you define the macros \underbraceleft, \underbraceright,
\underbracemiddle?

Dan

unread,
Aug 10, 2005, 12:52:04 PM8/10/05
to

pech...@cs.technion.ac.il wrote:
> The placement of _{xxx} depends on the number of lines that underbrace
> symbol should occupy, and in general it should be somewhere in the
> middle.
> If we have two lines, then _{xxx} should be at the end of the first
> line (or at the start of the second line). If we have three lines then
> _{xxx} should be in the middle of the second line.

Such a design would seem to be confusing at best and misleading at
worst (and probably hideous to look at). I wouldn't even try to
implement it, but rather would find some other way to label/describe
that group of items.

Can you point to an existing book or article that uses something like
that?


Dan

Jean-Côme Charpentier

unread,
Aug 10, 2005, 11:18:55 PM8/10/05
to
Dan wrote:
> pech...@cs.technion.ac.il wrote:
>
>>The placement of _{xxx} depends on the number of lines that underbrace
>>symbol should occupy, and in general it should be somewhere in the
>>middle.
>>If we have two lines, then _{xxx} should be at the end of the first
>>line (or at the start of the second line). If we have three lines then
>>_{xxx} should be in the middle of the second line.
>
>
> Such a design would seem to be confusing at best and misleading at
> worst (and probably hideous to look at).

I'm agree with you but the challenge was funny (even the result is
horrible) :-)

\documentclass{article}
\makeatletter
\newcommand*\Lupbracefill{%
$\m@th
\setbox\z@ \hbox{$\braceld$}%
\bracelu
\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill
$%
}
\newcommand*\LMupbracefill{%
$\m@th
\setbox\z@ \hbox{$\braceld$}%
\bracelu
\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill
\bracerd
\braceld
\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill
$%
}
\newcommand*\Mupbracefill{%
$\m@th
\setbox\z@ \hbox{$\braceld$}%
\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill
\bracerd
\braceld
\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill
$%
}
\newcommand*\MRupbracefill{%
$\m@th
\setbox\z@ \hbox{$\braceld$}%
\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill
\bracerd
\braceld
\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill
\braceru
$%
}
\newcommand*\Rupbracefill{%
$\m@th
\setbox\z@ \hbox{$\braceld$}%
\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill
\braceru
$%
}
\newcommand*\Eupbracefill{%
$\m@th
\setbox\z@ \hbox{$\braceld$}%
\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill
$%
}
\newcommand*\Allunderbrace[2]{%
\mathop{%
\vtop {%
\m@th
\ialign{%
##\crcr $\hfil \displaystyle {#2}\hfil$\crcr
\noalign{\kern 3\p@ \nointerlineskip}%
#1 \crcr
\noalign{\kern 3\p@}%
}%
}%
}\limits
}
\newcommand*\Lunderbrace{%
\Allunderbrace\Lupbracefill
}
\newcommand*\LMunderbrace{%
\Allunderbrace\LMupbracefill
}
\newcommand*\Munderbrace{%
\Allunderbrace\Mupbracefill
}
\newcommand*\MRunderbrace{%
\Allunderbrace\MRupbracefill
}
\newcommand*\Runderbrace{%
\Allunderbrace\Rupbracefill
}
\newcommand*\Eunderbrace{%
\Allunderbrace\Eupbracefill
}
\newcommand*\splitunderbrace[1]{%
\def\splitformula{#1}%
\@ifnextchar_{\split@underbrace}{\split@@underbrace}
}
\newif\ifsub
\def\split@underbrace_#1{%
\def\splitsub{#1}%
\subtrue
\split@@@underbrace
}
\def\split@@underbrace{%
\subfalse
\split@@@underbrace
}
\newcommand\split@@@underbrace{%
\count@=0
%% count@ = nb lines
\expandafter\SU@countbs\splitformula \\\@nil
\ifcase\count@
% impossible
\or
\ifsub
\underbrace{\splitformula}_{\splitsub}%
\else
\underbrace{\splitformula}%
\fi
\or
% 2
\setbox0=\hbox{$\displaystyle\@nameuse{SF@0}\phantom{\braceld}$}%
\setbox1=\hbox{$\displaystyle\@nameuse{SF@1}\phantom{\braceld}$}%
\ifdim\wd0>\wd1
\ifsub
\LMunderbrace{\box0}_{\splitsub}\\
\Runderbrace{\box1}%
\else
\Lunderbrace{\box0}\\
\MRunderbrace{\box1}%
\fi
\else
\ifsub
\else
\fi
\fi
\else
% >=3
\@tempcnta=\count@
\divide\@tempcnta \tw@
\ifodd\count@
% nb line is odd (one middle)
\advance\count@ \m@ne
% very left part
\setbox0=\hbox{$\displaystyle\@nameuse{SF@0}\phantom{\braceld}$}%
\Lunderbrace{\box0}\\
\@tempcntb=\@ne
% left parts
\loop
\ifnum\@tempcntb<\@tempcnta
\setbox0=\hbox{%
$\displaystyle\@nameuse{SF@\the\@tempcntb}\phantom{\braceld}$%
}%
\advance\@tempcntb \@ne
\Eunderbrace{\box0}\\
\repeat
\setbox0=\hbox{%
$\displaystyle\@nameuse{SF@\the\@tempcntb}\phantom{\braceld}$%
}%
\advance\@tempcntb \@ne
\ifsub
\Munderbrace{\box0}_{\splitsub}\\
\else
\Munderbrace{\box0}\\
\fi
\loop
\ifnum\@tempcntb<\count@
\setbox0=\hbox{%
$\displaystyle\@nameuse{SF@\the\@tempcntb}\phantom{\braceld}$%
}%
\advance\@tempcntb \@ne
\Eunderbrace{\box0}\\
\repeat
\setbox0=\hbox{%
$\displaystyle\@nameuse{SF@\the\@tempcntb}\phantom{\braceld}$%
}%
\Runderbrace{\box0}\\
\else
%nb line is even (two middles)
\advance\count@ \m@ne
\advance\@tempcnta \m@ne
% very left part
\setbox0=\hbox{$\displaystyle\@nameuse{SF@0}\phantom{\braceld}$}%
\Lunderbrace{\box0}\\
\@tempcntb=\@ne
% left parts
\loop
\ifnum\@tempcntb<\@tempcnta
\setbox0=\hbox{%
$\displaystyle\@nameuse{SF@\the\@tempcntb}\phantom{\braceld}$%
}%
\advance\@tempcntb \@ne
\Eunderbrace{\box0}\\
\repeat
\setbox0=\hbox{%
$\displaystyle\@nameuse{SF@\the\@tempcntb}\phantom{\braceld}$%
}%
\advance\@tempcntb \@ne
\setbox1=\hbox{%
$\displaystyle\@nameuse{SF@\the\@tempcntb}\phantom{\braceld}$%
}%
\advance\@tempcntb \@ne
\ifdim\wd0>\wd1
\ifsub
\Munderbrace{\box0}_{\splitsub}\\
\else
\Munderbrace{\box0}\\
\fi
\Eunderbrace{\box1}\\
\else
\Eunderbrace{\box0}\\
\ifsub
\Munderbrace{\box1}_{\splitsub}\\
\else
\Munderbrace{\box1}\\
\fi
\fi
\loop
\ifnum\@tempcntb<\count@
\setbox0=\hbox{%
$\displaystyle\@nameuse{SF@\the\@tempcntb}\phantom{\braceld}$%
}%
\advance\@tempcntb \@ne
\Eunderbrace{\box0}\\
\repeat
\setbox0=\hbox{%
$\displaystyle\@nameuse{SF@\the\@tempcntb}\phantom{\braceld}$%
}%
\Runderbrace{\box0}\\
\fi
\fi
}
\def\SU@countbs#1\\#2\@nil{%
\@namedef{SF@\the\count@}{$#1$}%
\def\SU@arg{#2}%
\advance\count@ \@ne
\ifx\empty\SU@arg
\let\next\@gobble
\else
\let\next\SU@countbs
\fi
\expandafter\next\SU@arg\@nil
}
\makeatother
\begin{document}
\parindent=0pt
$\splitunderbrace{a+b+c+d}_{xxx}$\par\bigskip

$\splitunderbrace{a+b+c+d+\\e+f+g+h}_{xxx}$\par\bigskip

$\splitunderbrace{a+b+c+d+\\e+f+g+h+\\i+j+k+l}_{xxx}$\par\bigskip

$\splitunderbrace{a+b+c+d+\\e+f+\\g+h+i+j+k+l+
\\m+n+o+p}_{xxx}$\par\bigskip

$\splitunderbrace{a+b+c+d+\\e+f+g+h+i+j+\\k+l+
\\m+n+o+p}_{xxx}$\par\bigskip

$\splitunderbrace{a+b+c+d+\\e+f+g+h+\\i+j+k+l+
\\m+n+o+p+\\q+r+s+t}_{xxx}$\par\bigskip

$\splitunderbrace{a+b+c+d+\\e+f+g+h+\\i+j+k+l+
\\m+n+o+p+\\q+r+s+t+\\u+v+w+x}_{xxx}$\par\bigskip

\end{document}

0 new messages