0

I am trying to adapt this answer on How to have overlapping under-braces and over-braces to overlapping overgroup/undergroup, but I seem to be getting unwanted extra space:

overlapping undergroup overgroup

Is there a way to get rid of the extra space between 2 and 3, or else to make the space more symmetrical (a little extra space between 2 and 3 and between 3 and 4 would be OK)?

\documentclass{article}
\usepackage{amsmath,mathtools}
\usepackage{mathabx}

\begin{document} \begin{align} \rlap{$\undergroup{\phantom{123}}$}12\overgroup{345} \ \mathrlap{\undergroup{\phantom{123}}}12\overgroup{345} \end{align} \end{document}

Earthliŋ
  • 1,140

1 Answers1

0

The space is generated by the \undergroup size, as you can see by removing the \phantom command: \undergroup add space

So you can smash both \undergroup and \overgroup, but with \mathclap to get them centered. Use this small hack to draw them a the good place:

\settowidth{\sometempdim}{123}        % get content width
\kern 0.5\sometempdim\relax           % move to the middle of the expression
\mathclap{\undergroup{\phantom{123}}} % typeset the \undergroup sign
\kern -0.5\sometempdim\relax          % go back
123                                   % typeset the expression

Define some dedicated commands for that:

\makeatletter
\newcommand*{\phantomundergroup}[1]{%
  \settowidth{\@tempdima}{#1}
  \kern 0.5\@tempdima\relax
  \mathclap{\undergroup{\phantom{#1}}}
  \kern -0.5\@tempdima\relax
}
\newcommand*{\phantomovergroup}[1]{%
  \settowidth{\@tempdima}{#1}
  \kern 0.5\@tempdima\relax
  \mathclap{\overgroup{\phantom{#1}}}
  \kern -0.5\@tempdima\relax
}
\makeatletter

Here I used \@tempdima, which is already defined by LaTeX (and hopefully not used internally by \mathclap, \overgroup nor \phantom). But you can use any length if you defined it before. The \makeatletter...\makeatother are necessary to handle the @ in \@tempdima name.

Full code:

\documentclass{article}
\usepackage{amsmath,mathtools}
\usepackage{mathabx}

\makeatletter \newcommand{\phantomundergroup}[1]{% \settowidth{@tempdima}{#1} \kern 0.5@tempdima\relax \mathclap{\undergroup{\phantom{#1}}} \kern -0.5@tempdima\relax } \newcommand{\phantomovergroup}[1]{% \settowidth{@tempdima}{#1} \kern 0.5@tempdima\relax \mathclap{\overgroup{\phantom{#1}}} \kern -0.5@tempdima\relax } \makeatletter

\begin{document} \begin{align} 12345\ \phantomundergroup{123}12 \phantomovergroup{345}345 \end{align} \end{document}

with phantomgroups

jlab
  • 1,834
  • 1
  • 13