Effectively, how to do “Underbrace” under two “Underbraces”?












8















Goal: I am trying to find a way to write an equation for:




enter image description here



However, I fail, or at least so far could not find a way, to add the last layer in the bottom for "magnetic flux" using underbrace.



Here is what I have so far,



$$
overbrace{ underbrace{S^1_A times S^1_B}_{E} times underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}
}^{text{ABCDEFG}}
$$


and my output is this:



enter image description here




Could you find a better way to do it? Effectively, how to do "Underbrace" under two "Underbraces"? Or maybe we can also try to use TikZ instead? (i.e. I don't mind to try other methods)




p.s. Another thing is that, in my case, the size of ABCDEFG is smaller than the S^1_A times S^1_B times S^1_C times mathbb{R} — is there a way to adjust the size of ABCDEFG and others?



Thank you for your help!!!










share|improve this question





























    8















    Goal: I am trying to find a way to write an equation for:




    enter image description here



    However, I fail, or at least so far could not find a way, to add the last layer in the bottom for "magnetic flux" using underbrace.



    Here is what I have so far,



    $$
    overbrace{ underbrace{S^1_A times S^1_B}_{E} times underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}
    }^{text{ABCDEFG}}
    $$


    and my output is this:



    enter image description here




    Could you find a better way to do it? Effectively, how to do "Underbrace" under two "Underbraces"? Or maybe we can also try to use TikZ instead? (i.e. I don't mind to try other methods)




    p.s. Another thing is that, in my case, the size of ABCDEFG is smaller than the S^1_A times S^1_B times S^1_C times mathbb{R} — is there a way to adjust the size of ABCDEFG and others?



    Thank you for your help!!!










    share|improve this question



























      8












      8








      8


      2






      Goal: I am trying to find a way to write an equation for:




      enter image description here



      However, I fail, or at least so far could not find a way, to add the last layer in the bottom for "magnetic flux" using underbrace.



      Here is what I have so far,



      $$
      overbrace{ underbrace{S^1_A times S^1_B}_{E} times underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}
      }^{text{ABCDEFG}}
      $$


      and my output is this:



      enter image description here




      Could you find a better way to do it? Effectively, how to do "Underbrace" under two "Underbraces"? Or maybe we can also try to use TikZ instead? (i.e. I don't mind to try other methods)




      p.s. Another thing is that, in my case, the size of ABCDEFG is smaller than the S^1_A times S^1_B times S^1_C times mathbb{R} — is there a way to adjust the size of ABCDEFG and others?



      Thank you for your help!!!










      share|improve this question
















      Goal: I am trying to find a way to write an equation for:




      enter image description here



      However, I fail, or at least so far could not find a way, to add the last layer in the bottom for "magnetic flux" using underbrace.



      Here is what I have so far,



      $$
      overbrace{ underbrace{S^1_A times S^1_B}_{E} times underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}
      }^{text{ABCDEFG}}
      $$


      and my output is this:



      enter image description here




      Could you find a better way to do it? Effectively, how to do "Underbrace" under two "Underbraces"? Or maybe we can also try to use TikZ instead? (i.e. I don't mind to try other methods)




      p.s. Another thing is that, in my case, the size of ABCDEFG is smaller than the S^1_A times S^1_B times S^1_C times mathbb{R} — is there a way to adjust the size of ABCDEFG and others?



      Thank you for your help!!!







      tikz-pgf math-mode horizontal-alignment underbrace






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 20 at 18:32









      Circumscribe

      4,5611432




      4,5611432










      asked Dec 20 at 17:36









      wonderich

      689618




      689618






















          3 Answers
          3






          active

          oldest

          votes


















          8














          documentclass{article}
          usepackage{mathtools,amssymb}
          begin{document}

          begin{gather*}
          overbrace{underbrace{S^1_A times S^1_B}_Etimes
          underbrace{S^1_Ctimesmathbb{R}}_{mathbb{CP}^{N-1}}}^{text{ABCDEFG}} \[-normalbaselineskip]
          underbrace{kern5em}_{text{magnetic flux}}
          end{gather*}

          end{document}


          enter image description here






          share|improve this answer





















          • Thanks +1, this looks elegant!
            – wonderich
            Dec 20 at 18:49



















          6














          Solution 1: adjust by hand.



          documentclass{article}
          usepackage{amsfonts}
          usepackage{mathtools}
          begin{document}
          [
          overbrace{ underbrace{S^1_A times S^1_B}_{E}
          makebox[7pt][c]{$underbrace{qquad~times~qquadvphantom{underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}}}_{text{magnetic flux}}$}
          underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}
          }^{text{ABCDEFG}}
          ]
          end{document}


          enter image description here



          Solution 2: TikZ.



          documentclass{article}
          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}
          begin{document}
          [
          tikzmarknode{l}{S^1_A times S^1_B}
          times
          tikzmarknode{r}{S^1_C times mathbb{R}}
          ]
          begin{tikzpicture}[overlay,remember picture,decoration={brace,raise=2pt},thick]
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$E$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer























          • This is amazing! I suppose I can also adjust the size of "brace" by the first or the second way?
            – wonderich
            Dec 20 at 18:35










          • @wonderich Yes. First way: change the quads. Second way: e.g. draw[decorate] ([xshift=-4pt]CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};` (Will be offline now.)
            – marmot
            Dec 20 at 18:42










          • @marmot: Isn't the fact that none of the braces in the second solution increase the depth of the equation potentially problematic?
            – Circumscribe
            Dec 20 at 18:45












          • @marmot, actually there is a problem, I cannot compile the 2nd option...
            – wonderich
            Dec 20 at 19:32










          • The error says: "undefined control sequence ... tikzmarknode"
            – wonderich
            Dec 20 at 19:33



















          4














          Solution 4 (or 5): measuring boxes



          I decided to create a slightly more basic version of the solution below.



          The macro bracetree, which I define below, creates the output you desire.
          It does does this by putting some of its arguments in box registers so that their widths can be measured.
          It then uses these width to insert the right amount of space at the right places to create braces with the correct widths



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <_ make @ usable in macro names
          newcommand*bracetree[6]{%
          begingroup %% <- limit scope of assignments
          sbox0{$m@thdisplaystyle #1$} %% <- store arguments in box registers
          sbox2{$m@th #4$}
          sbox4{$m@thdisplaystyle #3$}
          sbox6{$m@th #5$}
          hspace{dimexpr.5wd0-.5wd2} %% <- insert space
          underbrace{
          hspace{dimexpr-.5wd0+.5wd2} %% <- remove space
          underbrace{copy0}_{copy2}
          #2
          underbrace{copy4}_{copy6} %% <- remove space
          hspace{dimexpr-.5wd4+.5wd6}
          }_{textstyle #6}
          hspace{dimexpr.5wd4-.5wd6} %% <- insert space
          endgroup
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before
          begin{equation}
          overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {textnormal{magnetic fluxxxx}
          }
          }^{textstyletextnormal{ABCDEFG}}
          end{equation}
          Words after

          end{document}


          output



          A few notes:




          • ABCDEFG was smaller because the text above the overbrace is effectively like a superscript, and therefore set at the corresponding font size.
            This can be remedied by adding textstyle.
            I'm using textnormal instead of text because of the reasons outlined here.


          • I'm using positive and negative hspaces that cancel out precisely to set the width of the bottom underbrace.


          • I'm using mathrlap from mathtools to negate the horizontal space taken up by {N-1} because I think it looks better if the superscript is ignored for the purposes of brace placement and placement relative to braces.


          • sbox<box register>{<contents>} stores <contents> in a box register. These boxes can be printed with copy<box register> and their widths are given by wd<box register>.
            I'm using only even box registers because these are available as scratch registers.


          • m@th sets mathsurround (amount of horizontal space $…$) to zero. This is the default value, so it actually does nothing here. If you get rid of it you can also remove makeatletter and `makeatother.



          Solution 3 (or 4): black magic



          I made the version of bracetree below earlier by sort of taking apart the definition of the original underbrace. The results should mostly be the same, but it is a little harder to explain how this works (and probably for you to adapt).



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <- make @ usable in macro names
          newcommandbracetree[6]{%
          vtop{m@th
          sbox0{$mathstrutdisplaystyle #1$}%
          sbox2{$mathstrutdisplaystyle #3$}%
          sbox4{$mathstrut #4$}%
          sbox6{$mathstrut #5$}%
          ialign{##crcr
          $displaystylecopy0#2copy2$%
          crcr
          noalign{kern3p@nointerlineskip}%
          hbox to wd0{upbracefill}hfilhbox to wd2{upbracefill}%
          crcr
          hskip.5wd0hskip-.5wd4copy4hfilcopy6hskip-.5wd6hskip.5wd2
          crcr
          noalign{kern3p@nointerlineskip}%
          hskip.5wd0hskip-.5wd4upbracefillhskip-.5wd6hskip.5wd2
          crcr
          hskip.5wd0hskip-.5wd4hidewidthhbox{$#6$}hidewidthhskip-.5wd6hskip.5wd2
          crcr
          }%
          }%
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before.
          begin{equation}
          X = overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {text{magnetic flux}}
          }^{textstyletext{ABCDEFG}}
          end{equation}
          Words after.

          end{document}


          output



          I'm not really sure where to begin explaining this, but here it goes.





          • vtop creates a top aligned box: the first line of its contents will share a baseline with the surrounding equation. See here.


          • ialign is sort of like tabular: it allows you to align things next to each other or on top of each other.


          • crcr more or less does what \ does in a tabular environment


          • noalign{kern<length>} inserts a little vertical space


          • hskip<length> inserts horizontal space


          • hfil and hidewidth both insert a stretchable amount of space. The latter will be negative when necessary.


          • upbracefill fills the available space with an underbrace


          Solution 2.5: Tikz again



          I've modified marmot's answer (with his blessing).
          The difference between this version and his version is that this increases the depth of the equation (so "Words after" is actually below "magnetic flux").



          DISCLAIMER: This nests TikZ environments!



          Nesting TikZ environments is generally a bad idea because things like key values and bounding boxes can leak from the inner environment to the outer one and vice versa.
          While marmot believes it should be okay in this case, one should still be careful with this.
          See e.g this question and several pages linked to from there for more info.



          If a modified version of this code is used elsewhere it is not guaranteed to still work smoothly.



          documentclass{article}

          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}

          begin{document}

          noindent Words before
          begin{equation}
          X = begin{tikzpicture}[baseline,remember picture,decoration={brace,raise=2pt},thick]
          node[anchor=base] {$tikzmarknode{l}{S^1_A times S^1_B} times tikzmarknode{r}{S^1_C times mathbb{R}}$};
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$strut Evphantom{^{N}}$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{equation}
          Words after

          end{document}


          output






          share|improve this answer























          • Thanks +1, very nice!!!
            – wonderich
            Dec 20 at 23:53










          • @wonderich: Added a slightly more low-tech solution that'll probably be easier to modify if needed.
            – Circumscribe
            Dec 21 at 9:19











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f466729%2feffectively-how-to-do-underbrace-under-two-underbraces%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          8














          documentclass{article}
          usepackage{mathtools,amssymb}
          begin{document}

          begin{gather*}
          overbrace{underbrace{S^1_A times S^1_B}_Etimes
          underbrace{S^1_Ctimesmathbb{R}}_{mathbb{CP}^{N-1}}}^{text{ABCDEFG}} \[-normalbaselineskip]
          underbrace{kern5em}_{text{magnetic flux}}
          end{gather*}

          end{document}


          enter image description here






          share|improve this answer





















          • Thanks +1, this looks elegant!
            – wonderich
            Dec 20 at 18:49
















          8














          documentclass{article}
          usepackage{mathtools,amssymb}
          begin{document}

          begin{gather*}
          overbrace{underbrace{S^1_A times S^1_B}_Etimes
          underbrace{S^1_Ctimesmathbb{R}}_{mathbb{CP}^{N-1}}}^{text{ABCDEFG}} \[-normalbaselineskip]
          underbrace{kern5em}_{text{magnetic flux}}
          end{gather*}

          end{document}


          enter image description here






          share|improve this answer





















          • Thanks +1, this looks elegant!
            – wonderich
            Dec 20 at 18:49














          8












          8








          8






          documentclass{article}
          usepackage{mathtools,amssymb}
          begin{document}

          begin{gather*}
          overbrace{underbrace{S^1_A times S^1_B}_Etimes
          underbrace{S^1_Ctimesmathbb{R}}_{mathbb{CP}^{N-1}}}^{text{ABCDEFG}} \[-normalbaselineskip]
          underbrace{kern5em}_{text{magnetic flux}}
          end{gather*}

          end{document}


          enter image description here






          share|improve this answer












          documentclass{article}
          usepackage{mathtools,amssymb}
          begin{document}

          begin{gather*}
          overbrace{underbrace{S^1_A times S^1_B}_Etimes
          underbrace{S^1_Ctimesmathbb{R}}_{mathbb{CP}^{N-1}}}^{text{ABCDEFG}} \[-normalbaselineskip]
          underbrace{kern5em}_{text{magnetic flux}}
          end{gather*}

          end{document}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 20 at 18:48









          Herbert

          269k24407717




          269k24407717












          • Thanks +1, this looks elegant!
            – wonderich
            Dec 20 at 18:49


















          • Thanks +1, this looks elegant!
            – wonderich
            Dec 20 at 18:49
















          Thanks +1, this looks elegant!
          – wonderich
          Dec 20 at 18:49




          Thanks +1, this looks elegant!
          – wonderich
          Dec 20 at 18:49











          6














          Solution 1: adjust by hand.



          documentclass{article}
          usepackage{amsfonts}
          usepackage{mathtools}
          begin{document}
          [
          overbrace{ underbrace{S^1_A times S^1_B}_{E}
          makebox[7pt][c]{$underbrace{qquad~times~qquadvphantom{underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}}}_{text{magnetic flux}}$}
          underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}
          }^{text{ABCDEFG}}
          ]
          end{document}


          enter image description here



          Solution 2: TikZ.



          documentclass{article}
          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}
          begin{document}
          [
          tikzmarknode{l}{S^1_A times S^1_B}
          times
          tikzmarknode{r}{S^1_C times mathbb{R}}
          ]
          begin{tikzpicture}[overlay,remember picture,decoration={brace,raise=2pt},thick]
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$E$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer























          • This is amazing! I suppose I can also adjust the size of "brace" by the first or the second way?
            – wonderich
            Dec 20 at 18:35










          • @wonderich Yes. First way: change the quads. Second way: e.g. draw[decorate] ([xshift=-4pt]CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};` (Will be offline now.)
            – marmot
            Dec 20 at 18:42










          • @marmot: Isn't the fact that none of the braces in the second solution increase the depth of the equation potentially problematic?
            – Circumscribe
            Dec 20 at 18:45












          • @marmot, actually there is a problem, I cannot compile the 2nd option...
            – wonderich
            Dec 20 at 19:32










          • The error says: "undefined control sequence ... tikzmarknode"
            – wonderich
            Dec 20 at 19:33
















          6














          Solution 1: adjust by hand.



          documentclass{article}
          usepackage{amsfonts}
          usepackage{mathtools}
          begin{document}
          [
          overbrace{ underbrace{S^1_A times S^1_B}_{E}
          makebox[7pt][c]{$underbrace{qquad~times~qquadvphantom{underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}}}_{text{magnetic flux}}$}
          underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}
          }^{text{ABCDEFG}}
          ]
          end{document}


          enter image description here



          Solution 2: TikZ.



          documentclass{article}
          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}
          begin{document}
          [
          tikzmarknode{l}{S^1_A times S^1_B}
          times
          tikzmarknode{r}{S^1_C times mathbb{R}}
          ]
          begin{tikzpicture}[overlay,remember picture,decoration={brace,raise=2pt},thick]
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$E$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer























          • This is amazing! I suppose I can also adjust the size of "brace" by the first or the second way?
            – wonderich
            Dec 20 at 18:35










          • @wonderich Yes. First way: change the quads. Second way: e.g. draw[decorate] ([xshift=-4pt]CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};` (Will be offline now.)
            – marmot
            Dec 20 at 18:42










          • @marmot: Isn't the fact that none of the braces in the second solution increase the depth of the equation potentially problematic?
            – Circumscribe
            Dec 20 at 18:45












          • @marmot, actually there is a problem, I cannot compile the 2nd option...
            – wonderich
            Dec 20 at 19:32










          • The error says: "undefined control sequence ... tikzmarknode"
            – wonderich
            Dec 20 at 19:33














          6












          6








          6






          Solution 1: adjust by hand.



          documentclass{article}
          usepackage{amsfonts}
          usepackage{mathtools}
          begin{document}
          [
          overbrace{ underbrace{S^1_A times S^1_B}_{E}
          makebox[7pt][c]{$underbrace{qquad~times~qquadvphantom{underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}}}_{text{magnetic flux}}$}
          underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}
          }^{text{ABCDEFG}}
          ]
          end{document}


          enter image description here



          Solution 2: TikZ.



          documentclass{article}
          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}
          begin{document}
          [
          tikzmarknode{l}{S^1_A times S^1_B}
          times
          tikzmarknode{r}{S^1_C times mathbb{R}}
          ]
          begin{tikzpicture}[overlay,remember picture,decoration={brace,raise=2pt},thick]
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$E$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer














          Solution 1: adjust by hand.



          documentclass{article}
          usepackage{amsfonts}
          usepackage{mathtools}
          begin{document}
          [
          overbrace{ underbrace{S^1_A times S^1_B}_{E}
          makebox[7pt][c]{$underbrace{qquad~times~qquadvphantom{underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}}}_{text{magnetic flux}}$}
          underbrace{S^1_C times mathbb{R}}_{mathbb{CP}^{N-1}}
          }^{text{ABCDEFG}}
          ]
          end{document}


          enter image description here



          Solution 2: TikZ.



          documentclass{article}
          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}
          begin{document}
          [
          tikzmarknode{l}{S^1_A times S^1_B}
          times
          tikzmarknode{r}{S^1_C times mathbb{R}}
          ]
          begin{tikzpicture}[overlay,remember picture,decoration={brace,raise=2pt},thick]
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$E$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{document}


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 20 at 18:00

























          answered Dec 20 at 17:48









          marmot

          86.1k499183




          86.1k499183












          • This is amazing! I suppose I can also adjust the size of "brace" by the first or the second way?
            – wonderich
            Dec 20 at 18:35










          • @wonderich Yes. First way: change the quads. Second way: e.g. draw[decorate] ([xshift=-4pt]CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};` (Will be offline now.)
            – marmot
            Dec 20 at 18:42










          • @marmot: Isn't the fact that none of the braces in the second solution increase the depth of the equation potentially problematic?
            – Circumscribe
            Dec 20 at 18:45












          • @marmot, actually there is a problem, I cannot compile the 2nd option...
            – wonderich
            Dec 20 at 19:32










          • The error says: "undefined control sequence ... tikzmarknode"
            – wonderich
            Dec 20 at 19:33


















          • This is amazing! I suppose I can also adjust the size of "brace" by the first or the second way?
            – wonderich
            Dec 20 at 18:35










          • @wonderich Yes. First way: change the quads. Second way: e.g. draw[decorate] ([xshift=-4pt]CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};` (Will be offline now.)
            – marmot
            Dec 20 at 18:42










          • @marmot: Isn't the fact that none of the braces in the second solution increase the depth of the equation potentially problematic?
            – Circumscribe
            Dec 20 at 18:45












          • @marmot, actually there is a problem, I cannot compile the 2nd option...
            – wonderich
            Dec 20 at 19:32










          • The error says: "undefined control sequence ... tikzmarknode"
            – wonderich
            Dec 20 at 19:33
















          This is amazing! I suppose I can also adjust the size of "brace" by the first or the second way?
          – wonderich
          Dec 20 at 18:35




          This is amazing! I suppose I can also adjust the size of "brace" by the first or the second way?
          – wonderich
          Dec 20 at 18:35












          @wonderich Yes. First way: change the quads. Second way: e.g. draw[decorate] ([xshift=-4pt]CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};` (Will be offline now.)
          – marmot
          Dec 20 at 18:42




          @wonderich Yes. First way: change the quads. Second way: e.g. draw[decorate] ([xshift=-4pt]CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};` (Will be offline now.)
          – marmot
          Dec 20 at 18:42












          @marmot: Isn't the fact that none of the braces in the second solution increase the depth of the equation potentially problematic?
          – Circumscribe
          Dec 20 at 18:45






          @marmot: Isn't the fact that none of the braces in the second solution increase the depth of the equation potentially problematic?
          – Circumscribe
          Dec 20 at 18:45














          @marmot, actually there is a problem, I cannot compile the 2nd option...
          – wonderich
          Dec 20 at 19:32




          @marmot, actually there is a problem, I cannot compile the 2nd option...
          – wonderich
          Dec 20 at 19:32












          The error says: "undefined control sequence ... tikzmarknode"
          – wonderich
          Dec 20 at 19:33




          The error says: "undefined control sequence ... tikzmarknode"
          – wonderich
          Dec 20 at 19:33











          4














          Solution 4 (or 5): measuring boxes



          I decided to create a slightly more basic version of the solution below.



          The macro bracetree, which I define below, creates the output you desire.
          It does does this by putting some of its arguments in box registers so that their widths can be measured.
          It then uses these width to insert the right amount of space at the right places to create braces with the correct widths



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <_ make @ usable in macro names
          newcommand*bracetree[6]{%
          begingroup %% <- limit scope of assignments
          sbox0{$m@thdisplaystyle #1$} %% <- store arguments in box registers
          sbox2{$m@th #4$}
          sbox4{$m@thdisplaystyle #3$}
          sbox6{$m@th #5$}
          hspace{dimexpr.5wd0-.5wd2} %% <- insert space
          underbrace{
          hspace{dimexpr-.5wd0+.5wd2} %% <- remove space
          underbrace{copy0}_{copy2}
          #2
          underbrace{copy4}_{copy6} %% <- remove space
          hspace{dimexpr-.5wd4+.5wd6}
          }_{textstyle #6}
          hspace{dimexpr.5wd4-.5wd6} %% <- insert space
          endgroup
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before
          begin{equation}
          overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {textnormal{magnetic fluxxxx}
          }
          }^{textstyletextnormal{ABCDEFG}}
          end{equation}
          Words after

          end{document}


          output



          A few notes:




          • ABCDEFG was smaller because the text above the overbrace is effectively like a superscript, and therefore set at the corresponding font size.
            This can be remedied by adding textstyle.
            I'm using textnormal instead of text because of the reasons outlined here.


          • I'm using positive and negative hspaces that cancel out precisely to set the width of the bottom underbrace.


          • I'm using mathrlap from mathtools to negate the horizontal space taken up by {N-1} because I think it looks better if the superscript is ignored for the purposes of brace placement and placement relative to braces.


          • sbox<box register>{<contents>} stores <contents> in a box register. These boxes can be printed with copy<box register> and their widths are given by wd<box register>.
            I'm using only even box registers because these are available as scratch registers.


          • m@th sets mathsurround (amount of horizontal space $…$) to zero. This is the default value, so it actually does nothing here. If you get rid of it you can also remove makeatletter and `makeatother.



          Solution 3 (or 4): black magic



          I made the version of bracetree below earlier by sort of taking apart the definition of the original underbrace. The results should mostly be the same, but it is a little harder to explain how this works (and probably for you to adapt).



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <- make @ usable in macro names
          newcommandbracetree[6]{%
          vtop{m@th
          sbox0{$mathstrutdisplaystyle #1$}%
          sbox2{$mathstrutdisplaystyle #3$}%
          sbox4{$mathstrut #4$}%
          sbox6{$mathstrut #5$}%
          ialign{##crcr
          $displaystylecopy0#2copy2$%
          crcr
          noalign{kern3p@nointerlineskip}%
          hbox to wd0{upbracefill}hfilhbox to wd2{upbracefill}%
          crcr
          hskip.5wd0hskip-.5wd4copy4hfilcopy6hskip-.5wd6hskip.5wd2
          crcr
          noalign{kern3p@nointerlineskip}%
          hskip.5wd0hskip-.5wd4upbracefillhskip-.5wd6hskip.5wd2
          crcr
          hskip.5wd0hskip-.5wd4hidewidthhbox{$#6$}hidewidthhskip-.5wd6hskip.5wd2
          crcr
          }%
          }%
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before.
          begin{equation}
          X = overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {text{magnetic flux}}
          }^{textstyletext{ABCDEFG}}
          end{equation}
          Words after.

          end{document}


          output



          I'm not really sure where to begin explaining this, but here it goes.





          • vtop creates a top aligned box: the first line of its contents will share a baseline with the surrounding equation. See here.


          • ialign is sort of like tabular: it allows you to align things next to each other or on top of each other.


          • crcr more or less does what \ does in a tabular environment


          • noalign{kern<length>} inserts a little vertical space


          • hskip<length> inserts horizontal space


          • hfil and hidewidth both insert a stretchable amount of space. The latter will be negative when necessary.


          • upbracefill fills the available space with an underbrace


          Solution 2.5: Tikz again



          I've modified marmot's answer (with his blessing).
          The difference between this version and his version is that this increases the depth of the equation (so "Words after" is actually below "magnetic flux").



          DISCLAIMER: This nests TikZ environments!



          Nesting TikZ environments is generally a bad idea because things like key values and bounding boxes can leak from the inner environment to the outer one and vice versa.
          While marmot believes it should be okay in this case, one should still be careful with this.
          See e.g this question and several pages linked to from there for more info.



          If a modified version of this code is used elsewhere it is not guaranteed to still work smoothly.



          documentclass{article}

          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}

          begin{document}

          noindent Words before
          begin{equation}
          X = begin{tikzpicture}[baseline,remember picture,decoration={brace,raise=2pt},thick]
          node[anchor=base] {$tikzmarknode{l}{S^1_A times S^1_B} times tikzmarknode{r}{S^1_C times mathbb{R}}$};
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$strut Evphantom{^{N}}$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{equation}
          Words after

          end{document}


          output






          share|improve this answer























          • Thanks +1, very nice!!!
            – wonderich
            Dec 20 at 23:53










          • @wonderich: Added a slightly more low-tech solution that'll probably be easier to modify if needed.
            – Circumscribe
            Dec 21 at 9:19
















          4














          Solution 4 (or 5): measuring boxes



          I decided to create a slightly more basic version of the solution below.



          The macro bracetree, which I define below, creates the output you desire.
          It does does this by putting some of its arguments in box registers so that their widths can be measured.
          It then uses these width to insert the right amount of space at the right places to create braces with the correct widths



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <_ make @ usable in macro names
          newcommand*bracetree[6]{%
          begingroup %% <- limit scope of assignments
          sbox0{$m@thdisplaystyle #1$} %% <- store arguments in box registers
          sbox2{$m@th #4$}
          sbox4{$m@thdisplaystyle #3$}
          sbox6{$m@th #5$}
          hspace{dimexpr.5wd0-.5wd2} %% <- insert space
          underbrace{
          hspace{dimexpr-.5wd0+.5wd2} %% <- remove space
          underbrace{copy0}_{copy2}
          #2
          underbrace{copy4}_{copy6} %% <- remove space
          hspace{dimexpr-.5wd4+.5wd6}
          }_{textstyle #6}
          hspace{dimexpr.5wd4-.5wd6} %% <- insert space
          endgroup
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before
          begin{equation}
          overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {textnormal{magnetic fluxxxx}
          }
          }^{textstyletextnormal{ABCDEFG}}
          end{equation}
          Words after

          end{document}


          output



          A few notes:




          • ABCDEFG was smaller because the text above the overbrace is effectively like a superscript, and therefore set at the corresponding font size.
            This can be remedied by adding textstyle.
            I'm using textnormal instead of text because of the reasons outlined here.


          • I'm using positive and negative hspaces that cancel out precisely to set the width of the bottom underbrace.


          • I'm using mathrlap from mathtools to negate the horizontal space taken up by {N-1} because I think it looks better if the superscript is ignored for the purposes of brace placement and placement relative to braces.


          • sbox<box register>{<contents>} stores <contents> in a box register. These boxes can be printed with copy<box register> and their widths are given by wd<box register>.
            I'm using only even box registers because these are available as scratch registers.


          • m@th sets mathsurround (amount of horizontal space $…$) to zero. This is the default value, so it actually does nothing here. If you get rid of it you can also remove makeatletter and `makeatother.



          Solution 3 (or 4): black magic



          I made the version of bracetree below earlier by sort of taking apart the definition of the original underbrace. The results should mostly be the same, but it is a little harder to explain how this works (and probably for you to adapt).



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <- make @ usable in macro names
          newcommandbracetree[6]{%
          vtop{m@th
          sbox0{$mathstrutdisplaystyle #1$}%
          sbox2{$mathstrutdisplaystyle #3$}%
          sbox4{$mathstrut #4$}%
          sbox6{$mathstrut #5$}%
          ialign{##crcr
          $displaystylecopy0#2copy2$%
          crcr
          noalign{kern3p@nointerlineskip}%
          hbox to wd0{upbracefill}hfilhbox to wd2{upbracefill}%
          crcr
          hskip.5wd0hskip-.5wd4copy4hfilcopy6hskip-.5wd6hskip.5wd2
          crcr
          noalign{kern3p@nointerlineskip}%
          hskip.5wd0hskip-.5wd4upbracefillhskip-.5wd6hskip.5wd2
          crcr
          hskip.5wd0hskip-.5wd4hidewidthhbox{$#6$}hidewidthhskip-.5wd6hskip.5wd2
          crcr
          }%
          }%
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before.
          begin{equation}
          X = overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {text{magnetic flux}}
          }^{textstyletext{ABCDEFG}}
          end{equation}
          Words after.

          end{document}


          output



          I'm not really sure where to begin explaining this, but here it goes.





          • vtop creates a top aligned box: the first line of its contents will share a baseline with the surrounding equation. See here.


          • ialign is sort of like tabular: it allows you to align things next to each other or on top of each other.


          • crcr more or less does what \ does in a tabular environment


          • noalign{kern<length>} inserts a little vertical space


          • hskip<length> inserts horizontal space


          • hfil and hidewidth both insert a stretchable amount of space. The latter will be negative when necessary.


          • upbracefill fills the available space with an underbrace


          Solution 2.5: Tikz again



          I've modified marmot's answer (with his blessing).
          The difference between this version and his version is that this increases the depth of the equation (so "Words after" is actually below "magnetic flux").



          DISCLAIMER: This nests TikZ environments!



          Nesting TikZ environments is generally a bad idea because things like key values and bounding boxes can leak from the inner environment to the outer one and vice versa.
          While marmot believes it should be okay in this case, one should still be careful with this.
          See e.g this question and several pages linked to from there for more info.



          If a modified version of this code is used elsewhere it is not guaranteed to still work smoothly.



          documentclass{article}

          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}

          begin{document}

          noindent Words before
          begin{equation}
          X = begin{tikzpicture}[baseline,remember picture,decoration={brace,raise=2pt},thick]
          node[anchor=base] {$tikzmarknode{l}{S^1_A times S^1_B} times tikzmarknode{r}{S^1_C times mathbb{R}}$};
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$strut Evphantom{^{N}}$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{equation}
          Words after

          end{document}


          output






          share|improve this answer























          • Thanks +1, very nice!!!
            – wonderich
            Dec 20 at 23:53










          • @wonderich: Added a slightly more low-tech solution that'll probably be easier to modify if needed.
            – Circumscribe
            Dec 21 at 9:19














          4












          4








          4






          Solution 4 (or 5): measuring boxes



          I decided to create a slightly more basic version of the solution below.



          The macro bracetree, which I define below, creates the output you desire.
          It does does this by putting some of its arguments in box registers so that their widths can be measured.
          It then uses these width to insert the right amount of space at the right places to create braces with the correct widths



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <_ make @ usable in macro names
          newcommand*bracetree[6]{%
          begingroup %% <- limit scope of assignments
          sbox0{$m@thdisplaystyle #1$} %% <- store arguments in box registers
          sbox2{$m@th #4$}
          sbox4{$m@thdisplaystyle #3$}
          sbox6{$m@th #5$}
          hspace{dimexpr.5wd0-.5wd2} %% <- insert space
          underbrace{
          hspace{dimexpr-.5wd0+.5wd2} %% <- remove space
          underbrace{copy0}_{copy2}
          #2
          underbrace{copy4}_{copy6} %% <- remove space
          hspace{dimexpr-.5wd4+.5wd6}
          }_{textstyle #6}
          hspace{dimexpr.5wd4-.5wd6} %% <- insert space
          endgroup
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before
          begin{equation}
          overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {textnormal{magnetic fluxxxx}
          }
          }^{textstyletextnormal{ABCDEFG}}
          end{equation}
          Words after

          end{document}


          output



          A few notes:




          • ABCDEFG was smaller because the text above the overbrace is effectively like a superscript, and therefore set at the corresponding font size.
            This can be remedied by adding textstyle.
            I'm using textnormal instead of text because of the reasons outlined here.


          • I'm using positive and negative hspaces that cancel out precisely to set the width of the bottom underbrace.


          • I'm using mathrlap from mathtools to negate the horizontal space taken up by {N-1} because I think it looks better if the superscript is ignored for the purposes of brace placement and placement relative to braces.


          • sbox<box register>{<contents>} stores <contents> in a box register. These boxes can be printed with copy<box register> and their widths are given by wd<box register>.
            I'm using only even box registers because these are available as scratch registers.


          • m@th sets mathsurround (amount of horizontal space $…$) to zero. This is the default value, so it actually does nothing here. If you get rid of it you can also remove makeatletter and `makeatother.



          Solution 3 (or 4): black magic



          I made the version of bracetree below earlier by sort of taking apart the definition of the original underbrace. The results should mostly be the same, but it is a little harder to explain how this works (and probably for you to adapt).



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <- make @ usable in macro names
          newcommandbracetree[6]{%
          vtop{m@th
          sbox0{$mathstrutdisplaystyle #1$}%
          sbox2{$mathstrutdisplaystyle #3$}%
          sbox4{$mathstrut #4$}%
          sbox6{$mathstrut #5$}%
          ialign{##crcr
          $displaystylecopy0#2copy2$%
          crcr
          noalign{kern3p@nointerlineskip}%
          hbox to wd0{upbracefill}hfilhbox to wd2{upbracefill}%
          crcr
          hskip.5wd0hskip-.5wd4copy4hfilcopy6hskip-.5wd6hskip.5wd2
          crcr
          noalign{kern3p@nointerlineskip}%
          hskip.5wd0hskip-.5wd4upbracefillhskip-.5wd6hskip.5wd2
          crcr
          hskip.5wd0hskip-.5wd4hidewidthhbox{$#6$}hidewidthhskip-.5wd6hskip.5wd2
          crcr
          }%
          }%
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before.
          begin{equation}
          X = overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {text{magnetic flux}}
          }^{textstyletext{ABCDEFG}}
          end{equation}
          Words after.

          end{document}


          output



          I'm not really sure where to begin explaining this, but here it goes.





          • vtop creates a top aligned box: the first line of its contents will share a baseline with the surrounding equation. See here.


          • ialign is sort of like tabular: it allows you to align things next to each other or on top of each other.


          • crcr more or less does what \ does in a tabular environment


          • noalign{kern<length>} inserts a little vertical space


          • hskip<length> inserts horizontal space


          • hfil and hidewidth both insert a stretchable amount of space. The latter will be negative when necessary.


          • upbracefill fills the available space with an underbrace


          Solution 2.5: Tikz again



          I've modified marmot's answer (with his blessing).
          The difference between this version and his version is that this increases the depth of the equation (so "Words after" is actually below "magnetic flux").



          DISCLAIMER: This nests TikZ environments!



          Nesting TikZ environments is generally a bad idea because things like key values and bounding boxes can leak from the inner environment to the outer one and vice versa.
          While marmot believes it should be okay in this case, one should still be careful with this.
          See e.g this question and several pages linked to from there for more info.



          If a modified version of this code is used elsewhere it is not guaranteed to still work smoothly.



          documentclass{article}

          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}

          begin{document}

          noindent Words before
          begin{equation}
          X = begin{tikzpicture}[baseline,remember picture,decoration={brace,raise=2pt},thick]
          node[anchor=base] {$tikzmarknode{l}{S^1_A times S^1_B} times tikzmarknode{r}{S^1_C times mathbb{R}}$};
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$strut Evphantom{^{N}}$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{equation}
          Words after

          end{document}


          output






          share|improve this answer














          Solution 4 (or 5): measuring boxes



          I decided to create a slightly more basic version of the solution below.



          The macro bracetree, which I define below, creates the output you desire.
          It does does this by putting some of its arguments in box registers so that their widths can be measured.
          It then uses these width to insert the right amount of space at the right places to create braces with the correct widths



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <_ make @ usable in macro names
          newcommand*bracetree[6]{%
          begingroup %% <- limit scope of assignments
          sbox0{$m@thdisplaystyle #1$} %% <- store arguments in box registers
          sbox2{$m@th #4$}
          sbox4{$m@thdisplaystyle #3$}
          sbox6{$m@th #5$}
          hspace{dimexpr.5wd0-.5wd2} %% <- insert space
          underbrace{
          hspace{dimexpr-.5wd0+.5wd2} %% <- remove space
          underbrace{copy0}_{copy2}
          #2
          underbrace{copy4}_{copy6} %% <- remove space
          hspace{dimexpr-.5wd4+.5wd6}
          }_{textstyle #6}
          hspace{dimexpr.5wd4-.5wd6} %% <- insert space
          endgroup
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before
          begin{equation}
          overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {textnormal{magnetic fluxxxx}
          }
          }^{textstyletextnormal{ABCDEFG}}
          end{equation}
          Words after

          end{document}


          output



          A few notes:




          • ABCDEFG was smaller because the text above the overbrace is effectively like a superscript, and therefore set at the corresponding font size.
            This can be remedied by adding textstyle.
            I'm using textnormal instead of text because of the reasons outlined here.


          • I'm using positive and negative hspaces that cancel out precisely to set the width of the bottom underbrace.


          • I'm using mathrlap from mathtools to negate the horizontal space taken up by {N-1} because I think it looks better if the superscript is ignored for the purposes of brace placement and placement relative to braces.


          • sbox<box register>{<contents>} stores <contents> in a box register. These boxes can be printed with copy<box register> and their widths are given by wd<box register>.
            I'm using only even box registers because these are available as scratch registers.


          • m@th sets mathsurround (amount of horizontal space $…$) to zero. This is the default value, so it actually does nothing here. If you get rid of it you can also remove makeatletter and `makeatother.



          Solution 3 (or 4): black magic



          I made the version of bracetree below earlier by sort of taking apart the definition of the original underbrace. The results should mostly be the same, but it is a little harder to explain how this works (and probably for you to adapt).



          documentclass{article}

          usepackage{amsmath} %% <- not explicitly needed
          usepackage{amsfonts} %% <- for mathbb
          usepackage{mathtools} %% <- for mathrlap, loads amsmath

          makeatletter %% <- make @ usable in macro names
          newcommandbracetree[6]{%
          vtop{m@th
          sbox0{$mathstrutdisplaystyle #1$}%
          sbox2{$mathstrutdisplaystyle #3$}%
          sbox4{$mathstrut #4$}%
          sbox6{$mathstrut #5$}%
          ialign{##crcr
          $displaystylecopy0#2copy2$%
          crcr
          noalign{kern3p@nointerlineskip}%
          hbox to wd0{upbracefill}hfilhbox to wd2{upbracefill}%
          crcr
          hskip.5wd0hskip-.5wd4copy4hfilcopy6hskip-.5wd6hskip.5wd2
          crcr
          noalign{kern3p@nointerlineskip}%
          hskip.5wd0hskip-.5wd4upbracefillhskip-.5wd6hskip.5wd2
          crcr
          hskip.5wd0hskip-.5wd4hidewidthhbox{$#6$}hidewidthhskip-.5wd6hskip.5wd2
          crcr
          }%
          }%
          }
          makeatother %% <- revert @

          begin{document}

          noindent Words before.
          begin{equation}
          X = overbrace{
          bracetree{S^1_A times S^1_B}{times}{S^1_C times mathbb{R}}
          {E}{mathbb{CP}^{mathrlap{N-1}}}
          {text{magnetic flux}}
          }^{textstyletext{ABCDEFG}}
          end{equation}
          Words after.

          end{document}


          output



          I'm not really sure where to begin explaining this, but here it goes.





          • vtop creates a top aligned box: the first line of its contents will share a baseline with the surrounding equation. See here.


          • ialign is sort of like tabular: it allows you to align things next to each other or on top of each other.


          • crcr more or less does what \ does in a tabular environment


          • noalign{kern<length>} inserts a little vertical space


          • hskip<length> inserts horizontal space


          • hfil and hidewidth both insert a stretchable amount of space. The latter will be negative when necessary.


          • upbracefill fills the available space with an underbrace


          Solution 2.5: Tikz again



          I've modified marmot's answer (with his blessing).
          The difference between this version and his version is that this increases the depth of the equation (so "Words after" is actually below "magnetic flux").



          DISCLAIMER: This nests TikZ environments!



          Nesting TikZ environments is generally a bad idea because things like key values and bounding boxes can leak from the inner environment to the outer one and vice versa.
          While marmot believes it should be okay in this case, one should still be careful with this.
          See e.g this question and several pages linked to from there for more info.



          If a modified version of this code is used elsewhere it is not guaranteed to still work smoothly.



          documentclass{article}

          usepackage{amsfonts,amsmath}
          usepackage{tikz}
          usetikzlibrary{tikzmark,decorations.pathreplacing}

          begin{document}

          noindent Words before
          begin{equation}
          X = begin{tikzpicture}[baseline,remember picture,decoration={brace,raise=2pt},thick]
          node[anchor=base] {$tikzmarknode{l}{S^1_A times S^1_B} times tikzmarknode{r}{S^1_C times mathbb{R}}$};
          draw[decorate] (l.north west) -- (r.north east) node[midway,above=3pt](ABC){ABCDEFG};
          draw[decorate] (l.south east) -- (l.south west) node[midway,below=3pt](E){$strut Evphantom{^{N}}$};
          draw[decorate] (r.south east) -- (r.south west) node[midway,below=3pt](CP){$mathbb{CP}^{N-1}$};
          draw[decorate] (CP.south east) -- (E.south west|-CP.south) node[midway,below=3pt]{magnetic flux};
          end{tikzpicture}
          end{equation}
          Words after

          end{document}


          output







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 23 at 0:08

























          answered Dec 20 at 20:52









          Circumscribe

          4,5611432




          4,5611432












          • Thanks +1, very nice!!!
            – wonderich
            Dec 20 at 23:53










          • @wonderich: Added a slightly more low-tech solution that'll probably be easier to modify if needed.
            – Circumscribe
            Dec 21 at 9:19


















          • Thanks +1, very nice!!!
            – wonderich
            Dec 20 at 23:53










          • @wonderich: Added a slightly more low-tech solution that'll probably be easier to modify if needed.
            – Circumscribe
            Dec 21 at 9:19
















          Thanks +1, very nice!!!
          – wonderich
          Dec 20 at 23:53




          Thanks +1, very nice!!!
          – wonderich
          Dec 20 at 23:53












          @wonderich: Added a slightly more low-tech solution that'll probably be easier to modify if needed.
          – Circumscribe
          Dec 21 at 9:19




          @wonderich: Added a slightly more low-tech solution that'll probably be easier to modify if needed.
          – Circumscribe
          Dec 21 at 9:19


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f466729%2feffectively-how-to-do-underbrace-under-two-underbraces%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Сан-Квентин

          Алькесар

          Josef Freinademetz