Typesetting Multiple Overlapping Braces in LaTeX

Click For Summary

Discussion Overview

The discussion revolves around typesetting multiple overlapping braces in LaTeX, specifically focusing on how to achieve this for mathematical expressions. Participants explore various methods to create underbraces and overbraces that may overlap, addressing both the technical aspects and potential issues encountered in the process.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant seeks a method to typeset an expression with multiple overlapping underbraces, providing an initial example.
  • Another participant suggests a nested underbrace approach but notes that the second brace should start under a specific element and end at another.
  • A different participant proposes using the makebox command to create a zero-width box for positioning braces, explaining the mechanics behind it.
  • Concerns are raised about the appearance of duplicate content when overlapping braces are used, with suggestions to use the phantom command to avoid visibility issues.
  • One participant shares a complex example from a Wikipedia article, noting that it differs from the original request but is still relevant.
  • Questions arise regarding the use of dollar signs in LaTeX code, with participants discussing their purpose in denoting math mode.
  • Errors related to missing dollar signs in LaTeX code are reported, prompting discussions about the leniency of the LaTeX engine.
  • Clarifications are provided about the nesting of equation environments and the treatment of content within makebox commands.

Areas of Agreement / Disagreement

Participants express varying methods and approaches to achieve the desired typesetting, with no consensus on a single solution. Some participants agree on the utility of the makebox command, while others raise questions about its implementation and effects.

Contextual Notes

Participants mention potential issues with alignment and visibility of overlapping braces, as well as the need for careful handling of math mode versus text mode in LaTeX. There are also references to specific LaTeX commands and their effects that may depend on the context of use.

Who May Find This Useful

This discussion may be useful for individuals interested in advanced LaTeX typesetting techniques, particularly those working with mathematical expressions and seeking to create complex visual representations in their documents.

rsq_a
Messages
103
Reaction score
1
I'd like to typeset an expression like,

a + b + c + d = e

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

\underbrace{a + b}_\textrm{brace 1} + c + d = e

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?
 
Physics news on Phys.org
\underbrace{\underbrace{a + b}_\textrm{brace 1} + c + d}_\textrm{brace 2}= e
 
CRGreathouse said:
\underbrace{\underbrace{a + b}_\textrm{brace 1} + c + d}_\textrm{brace 2}= e

I originally did that (but then deleted it). He is asking for the brace to start under b and end at d.
 
Hi rsq_a,


rsq_a said:
I'd like to typeset an expression like,

a + b + c + d = e

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

\underbrace{a + b}_\textrm{brace 1} + c + d = e

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:

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




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




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


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:

<br /> {\rm neutrons} + {\rm protons} + {\rm electrons}<br />

Now put in the first underbrace:

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

output:

<br /> {\rm neutrons} + \underbrace{ {\rm protons} + {\rm electrons} }_{\rm charged}<br />


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:

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



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:

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


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.
 
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:

<br /> \overbrace{\rho \Big(<br /> \underbrace{\frac{\partial \mathbf{v}}{\partial t}}_{<br /> \begin{smallmatrix}<br /> \text{Unsteady}\\<br /> \text{acceleration}<br /> \end{smallmatrix}} + <br /> \underbrace{\mathbf{v} \cdot \nabla \mathbf{v}}_{<br /> \begin{smallmatrix}<br /> \text{Convective} \\<br /> \text{acceleration}<br /> \end{smallmatrix}}\Big)}^{\text{Inertia}} =<br /> \underbrace{-\nabla p}_{<br /> \begin{smallmatrix}<br /> \text{Pressure} \\<br /> \text{gradient}<br /> \end{smallmatrix}} + <br /> \underbrace{\mu \nabla^2 \mathbf{v}}_{\text{Viscosity}} + <br /> \underbrace{\mathbf{f}}_{<br /> \begin{smallmatrix}<br /> \text{Other} \\<br /> \text{forces}<br /> \end{smallmatrix}}<br />
 
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.
 
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}
?
 
Of course I was using my local LaTex installation.
 
Hi zslevi,

zslevi said:
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.
 
  • #10
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?
 
  • #11
zslevi said:
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).
 
  • #12
Thanks for the explanation.
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 9 ·
Replies
9
Views
6K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K