6

Is there a way to instruct LaTeX to ignore the text in the \underbrace for purposes of kerning the equation in math mode?

\begin{align}
    &x
    \underbrace{(4-3y)}_
    {\text{Positive $\forall y \in [0,1]$}}
    +4y -1
\end{align}

enter image description here .

I know that I can use \mkern-30:

\begin{align}
    x
    \mkern-30 % Adding this is a sub-par solution
    \underbrace{(4-3y)}_
    {\text{Positive $\forall y \in [0,1]$}}
    \mkern-26 % Adding this is a sub-par solution
    +4y -1
\end{align}

enter image description here

but finding the exact number to work out how to fix the kerning is obviously not fun.

Is there a better way?

2
  • 6
    use mathtools and its \mathclap{...} macro: \underbrace{....}_{\mathclap{...}}, and next time please post a full minimal example, not just a sniplet, then it is a lot easier for others to test your code
    – daleif
    Commented May 23, 2019 at 11:25
  • Noted, daleif. Thank's a ton!
    – Toldry
    Commented May 23, 2019 at 11:32

2 Answers 2

6

The subscript can be set in a zero-width box. The size of the subscript should be set explicitly. This results in the same output as \mathclap from mathtools.

MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
\begin{align}
    &x
   \underbrace{(4-3y)}_
    {\text{Positive $\forall y \in [0,1]$}}
    +4y -1
\end{align}
\begin{align}
    &x
   \underbrace{(4-3y)}_
    {\makebox[0pt]{\scriptsize\text{Positive $\forall y \in [0,1]$}}}
    +4y -1
\end{align}
\begin{align}
    &x
   \underbrace{(4-3y)}_
    {\mathclap{\text{Positive $\forall y \in [0,1]$}}}
    +4y -1
\end{align}
\end{document}

Result:

enter image description here

7

In this particular case \mathclap is not necessary:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
x{\underbrace{(4-3y)}_{\substack{\text{positive}\\[1pt] \forall y \in [0,1]}}} + 4y - 1
\end{equation*}

\end{document}

enter image description here

Compare with

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

\begin{document}

\begin{equation*}
x{\underbrace{(4-3y)}_{\mathclap{\text{positive $\forall y \in [0,1]$}}}} + 4y - 1
\end{equation*}

\end{document}

enter image description here

Note, anyway, the additional pair of braces around the whole

{\underbrace{...}_{...}}

construction: they're necessary in order to get the right spacing.

4
  • 1
    +1 for the "extra set of braces" trick, which converts the \underbrace atom effectively into \mathord, I suppose. Or maybe it's deeper than that. Commented May 23, 2019 at 11:49
  • @StevenB.Segletes Yes: you can see the wrong spacing in the other answer.
    – egreg
    Commented May 23, 2019 at 11:50
  • What is the purpose of the [1pt] in the first solution?
    – Toldry
    Commented May 23, 2019 at 11:55
  • 1
    @Toldry To separate a bit the two lines, they would be too crowded otherwise.
    – egreg
    Commented May 23, 2019 at 11:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .