TransWikia.com

Underbracket and overbracket intersecting each other

TeX - LaTeX Asked by cstml on June 7, 2021

I cannot seem to find a way to achieve the result I want which is best portrayed by this sketch diagram:

x spanning two underbrackets

This is because if I add an overbracket it is closed by the underbracket } before it gets to the second group of underbracket.

$w = 
    underbracket[0.75pt]{aaa...a}_{n}
    underbracket[0.75pt]{aaa...a}_{m}
    underbracket[0.75pt]{bbb...b}_{n}
    underbracket[0.75pt]{aaa...a}_{m}
    underbracket[0.75pt]{bbb...b}_{n}
$

Solution:

As suggested in this post: How to have overlapping under-braces and over-braces

Solution

$
w = 
    rlap{phantom{aaa}$overbracket[0.75pt]{phantom{aaaaa}}^x$}
    underbracket[0.75pt]{aaa...a}_{n}
    underbracket[0.75pt]{aaa...a}_{m}
    underbracket[0.75pt]{bbb...b}_{n}
    underbracket[0.75pt]{aaa...a}_{m}
    underbracket[0.75pt]{bbb...b}_{n}
$

Note that the letters added in the phantom do not matter.

One Answer

Probably the posts from Mico's link are the best way to go, but here is an alternative that allows you to avoid typing the text twice: tikzmark. I actually do not think that this method is superior in this very case because

  1. you have to load another package,
  2. you need to insert a vphantom to get the vertical space right as an overlay tikzpicture does not insert space, and
  3. you need to give each tikzmarknode a unique label.

However, it is an alternative, and as soon as you want a more fancy bracket (bent, dashed, whatever) this method is likely to continue to give you what you want.

documentclass{article}
usepackage{mathtools}
usepackage{tikz}
usetikzlibrary{tikzmark}
begin{document}
Some text to test the vertical space.

$
w = vphantom{overbracket[0.75pt]{a}^{x}}% to fix the vertical space
    underbracket[0.75pt]{aatikzmarknode{a1}{a}dots a}_{n}
    underbracket[0.75pt]{atikzmarknode{a2}{a}adots a}_{m}
    underbracket[0.75pt]{bbbdots b}_{n}
    underbracket[0.75pt]{aaadots a}_{m}
    underbracket[0.75pt]{bbbdots b}_{n}
    begin{tikzpicture}[overlay,remember picture]
     draw[line width=0.75pt] (a1.north east) -- ++ (0,0.8ex)
      -| node[pos=0.25,above]{$x$} (a2.north east);
    end{tikzpicture}
$

Some text to test the vertical space.
[w = vphantom{overbracket[0.75pt]{a}^{x}}% to fix the vertical space
    underbracket[0.75pt]{aatikzmarknode{a3}{a}dots a}_{n}
    underbracket[0.75pt]{atikzmarknode{a4}{a}adots a}_{m}
    underbracket[0.75pt]{bbbdots b}_{n}
    underbracket[0.75pt]{aaadots a}_{m}
    underbracket[0.75pt]{bbbdots b}_{n}
    begin{tikzpicture}[overlay,remember picture]
     draw[line width=0.75pt] (a3.north east) -- ++ (0,0.8ex)
      -| node[pos=0.25,above]{$x$} (a4.north east);
    end{tikzpicture}
]
Some text to test the vertical space.
end{document}

enter image description here

Correct answer by user230294 on June 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP