Register to reply

Underbrace in LaTeX

by rsq_a
Tags: latex, underbrace
Share this thread:
rsq_a
#1
Oct16-08, 08:58 AM
P: 110
I'd like to typeset an expression like,

[tex]a + b + c + d = e[/tex]

The problem is I'd like to use multiple underbraces (or perhaps overbraces) which may also overlap. For example,

[tex]\underbrace{a + b}_\textrm{brace 1} + c + d = e[/tex]

is the first brace. But I'd also like to have a second brace which underlines b, c, and d (and lies below the first brace).

How would I do that?
Phys.Org News Partner Science news on Phys.org
World's largest solar boat on Greek prehistoric mission
Google searches hold key to future market crashes
Mineral magic? Common mineral capable of making and breaking bonds
CRGreathouse
#2
Oct16-08, 10:09 AM
Sci Advisor
HW Helper
P: 3,684
[tex]\underbrace{\underbrace{a + b}_\textrm{brace 1} + c + d}_\textrm{brace 2}= e[/tex]
cristo
#3
Oct16-08, 10:28 AM
Mentor
cristo's Avatar
P: 8,308
Quote Quote by CRGreathouse View Post
[tex]\underbrace{\underbrace{a + b}_\textrm{brace 1} + c + d}_\textrm{brace 2}= e[/tex]
I originally did that (but then deleted it). He is asking for the brace to start under b and end at d.

alphysicist
#4
Oct16-08, 11:59 PM
HW Helper
P: 2,249
Underbrace in LaTeX

Hi rsq_a,


Quote Quote by rsq_a View Post
I'd like to typeset an expression like,

[tex]a + b + c + d = e[/tex]

The problem is I'd like to use multiple underbraces (or perhaps overbraces) which may also overlap. For example,

[tex]\underbrace{a + b}_\textrm{brace 1} + c + d = e[/tex]

is the first brace. But I'd also like to have a second brace which underlines b, c, and d (and lies below the first brace).

How would I do that?
How about these:

[tex]
a + \underbrace{b \makebox[0pt][r]{$\displaystyle{\underbrace{\phantom{a+b}}_\textrm{brace 1}}$}
+ c + d}_\textrm{brace 2} = e
[/tex]




[tex]
\underbrace{a + \makebox[0pt][l]{$\displaystyle{\underbrace{\phantom{b+c+d}}_\textrm{ brace 2}}$} b}_\textrm{brace 1} + c + d = e
[/tex]




[tex]
\underbrace{a + \makebox[0pt][l]{$\displaystyle{\overbrace{\phantom{b+c+d}}^\textrm{ brace 2}}$} b}_\textrm{brace 1} + c + d = e
[/tex]


You can say that the makebox command here is causing the inner brace to have a width of zero, for the purpose of calculating the outer brace. Let me show you the steps:

Let's say you start with this bit of Latex code:

{\rm neutrons} + {\rm protons} + {\rm electrons}

which if you Latex it gives the output:

[tex]
{\rm neutrons} + {\rm protons} + {\rm electrons}
[/tex]

Now put in the first underbrace:

{\rm neutrons} + \underbrace{ {\rm protons} + {\rm electrons} }_{\rm charged}

output:

[tex]
{\rm neutrons} + \underbrace{ {\rm protons} + {\rm electrons} }_{\rm charged}
[/tex]


So that's good. Now create a zero width box at the point where one end of the second underbrace goes, like this (with the new stuff in bold):

{\rm neutrons} + \underbrace{ {\rm protons}
\makebox[0pt][r]{$\underbrace{ {\rm neutrons} + {\rm protons} }_{\rm nucleons} }+ {\rm electrons} }_{\rm charged}

output:

[tex]
{\rm neutrons} + \underbrace{ {\rm protons}
\makebox[0pt][r]{$\underbrace{ {\rm neutrons} + {\rm protons} }_{\rm nucleons} }
+ {\rm electrons} }_{\rm charged}
[/tex]



I noticed that this last version looks fine on the forum, but what's really happening is that there are two copies of {\rm neutrons} + {\rm protons}; they are just right on top of each other. Sometimes they won't line up perfectly, so to make sure that you never see the duplicate contents, you can use the phantom command:

{\rm neutrons} + \underbrace{ {\rm protons}
\makebox[0pt][r]{$\underbrace{ \phantom{ {\rm neutrons} + {\rm protons} } }_{\rm nucleons} }+ {\rm electrons} }_{\rm charged}

output:

[tex]
{\rm neutrons} + \underbrace{ {\rm protons}
\makebox[0pt][r]{$\underbrace{ \phantom{ {\rm neutrons} + {\rm protons}} }_{\rm nucleons} }
+ {\rm electrons} }_{\rm charged}
[/tex]


Depending on what is in your equation, you might also want to use the displaystyle command right after the $ in the makebox (like I have in my first several examples). Also in my own work I have sometimes had to explicitly add a space or two to make everything line up correctly.
rsq_a
#5
Oct29-08, 03:48 AM
P: 110
I forgot to thank you for this (have yet to return to writing). I also spotted this in a Wikipedia article -- not as easy as your technique (and not the kind of braces I wanted), but it'd be nice to keep the info for future reference:

[tex]
\overbrace{\rho \Big(
\underbrace{\frac{\partial \mathbf{v}}{\partial t}}_{
\begin{smallmatrix}
\text{Unsteady}\\
\text{acceleration}
\end{smallmatrix}} +
\underbrace{\mathbf{v} \cdot \nabla \mathbf{v}}_{
\begin{smallmatrix}
\text{Convective} \\
\text{acceleration}
\end{smallmatrix}}\Big)}^{\text{Inertia}} =
\underbrace{-\nabla p}_{
\begin{smallmatrix}
\text{Pressure} \\
\text{gradient}
\end{smallmatrix}} +
\underbrace{\mu \nabla^2 \mathbf{v}}_{\text{Viscosity}} +
\underbrace{\mathbf{f}}_{
\begin{smallmatrix}
\text{Other} \\
\text{forces}
\end{smallmatrix}}
[/tex]
zslevi
#6
Mar7-10, 03:55 PM
P: 8
Can somebody tell me that in previous examples what does the $ sign do before the \underbrace tag? At first I thought it's a typo.
zslevi
#7
Mar7-10, 03:58 PM
P: 8
And I get the following error message for
$$
{\rm neutrons} + \underbrace{ {\rm protons}
\makebox[0pt][r]{$\underbrace{ {\rm neutrons} + {\rm protons} }_{\rm nucleons} }+ {\rm electrons} }_{\rm charged}
$$


! Missing $ inserted.
<inserted text>
$
l.14 + {\rm electrons} }
_{\rm charged}
?
zslevi
#8
Mar7-10, 04:20 PM
P: 8
Of course I was using my local LaTex installation.
alphysicist
#9
Mar7-10, 06:10 PM
HW Helper
P: 2,249
Hi zslevi,

Quote Quote by zslevi View Post
And I get the following error message for
$$
{\rm neutrons} + \underbrace{ {\rm protons}
\makebox[0pt][r]{$\underbrace{ {\rm neutrons} + {\rm protons} }_{\rm nucleons} }+ {\rm electrons} }_{\rm charged}
$$


! Missing $ inserted.
<inserted text>
$
l.14 + {\rm electrons} }
_{\rm charged}
?
There is a typo in my post; I left out a $ that was needed. (If you look at the first three examples at the beginning of my post you'll see matching single dollar signs the way they should be.) It seems that the LaTeX engine here is lenient and allowed my mistake to go through.

If you use this for your example:

$$
{\rm neutrons} + \underbrace{ {\rm protons}
\makebox[0pt][r]{$\underbrace{ {\rm neutrons} + {\rm protons} }_{\rm nucleons} $}+ {\rm electrons} }_{\rm charged}
$$

I believe it will work fine.
zslevi
#10
Mar8-10, 06:39 AM
P: 8
Now it works fine, thanks.
However I still don't get what those single dollar signs are doing: are you nesting equation environments, or what?
alphysicist
#11
Mar8-10, 02:20 PM
HW Helper
P: 2,249
Quote Quote by zslevi View Post
Now it works fine, thanks.
However I still don't get what those single dollar signs are doing: are you nesting equation environments, or what?
My understanding is that the makebox argument is in text mode; for example if you look at this:

$$ xyz\makebox{abc}mno$$

you can see abc is treated as normal text, not equation symbols. But I wanted my box to contain equation components, so I had to get in (inline) equation mode and used the dollar signs (just like you would if you wanted math inside a paragraph of text).
zslevi
#12
Mar9-10, 01:26 PM
P: 8
Thanks for the explanation.


Register to reply

Related Discussions
Install MikTex first before you install texmaker or texniccenter Math & Science Software 4
Free programs that use Latex that I could insert in a ms word doc and attach Math & Science Software 3
I need help with Latex Math & Science Software 15
LaTeX help General Math 1
LaTex for my science fair project Introductory Physics Homework 1