16

I have found that using an \underbrace on a term in an equation causes the spacing of the following terms to be changed, in particular, the + is moved closer to the \dot{m}. This seems to be distinct from the problem in Oversized \underbrace's label causes unwanted spacing because

  1. the amount of space is getting smaller
  2. the label under the brace is not larger than the brace
  3. trying \mathclap as suggested in that question doesn't help

I noticed this problem when putting together a presentation in beamer, but I'm able to reproduce it in the standard article class as well. Changing the font doesn't help either (I noticed the problem with TeX Gyre Pagella Math). How can I avoid changing the spacing surrounding an underbrace?

\documentclass{article}
\begin{document}
\[ \dot{W}_{cv} + \dot{m} \]
\[ \underbrace{\dot{W}_{cv}}_{=0} + \dot{m} \]
\[ \underbrace{\dot{W}}_{=0} + \dot{m} \]
\end{document}

enter image description here

15

The definition of \underbrace in latex.ltx is essentially borrowed from Plain TeX:

\def\underbrace#1{\mathop{\vtop{\m@th\ialign{##\crcr
   $\hfil\displaystyle{#1}\hfil$\crcr
   \noalign{\kern3\p@\nointerlineskip}%
   \upbracefill\crcr\noalign{\kern3\p@}}}}\limits}

This allows the syntax

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

but has the consequence you can see in your example.

The spacing would be the same as with

\sin+x

enter image description here

Solution: add braces, which make the object into an ordinary atom.

\documentclass{article}
\begin{document}
\[ \dot{W}_{cv} + \dot{m} \]
\[ {\underbrace{\dot{W}_{cv}}_{=0}} + \dot{m} \]
\[ {\underbrace{\dot{W}}_{=0}} + \dot{m} \]
\end{document}

enter image description here

The proper syntax for LaTeX would be

\Underbrace{label}{formula}

and you can obtain it by saying

\newcommand{\Underbrace}[2]{{\underbrace{#2}_{#1}}}
  • 1
    my reaction to the spacing was that this is being treated as a unary plus, so wrapping braces around the entire underbrace expression would be the logical solution. not as detailed technically as your explanation, but perhaps easier to remember. – barbara beeton Jan 19 '15 at 19:02
5

The problem here is that the \underbrace (also \overbrace) is constructed using a minimum of four glyphs: The two outer upward curls and the middle/inner downward curls. If the content to be "underbraced" is wider than this, padding is inserted in the form of a horizontal fill line on both sides of the middle/inner downward curl. If content is smaller than this, then that's what it is and you'll have to tweak things manually to suit your needs.

enter image description here

\documentclass{article}
\usepackage{xcolor}
\newlength{\mylen}
\begin{document}
\[ \dot{W}_{cv} +\smash{\rlap{\color{red}\rule[-9\baselineskip]{.4pt}{10\baselineskip}}} \dot{m} \]
\[ \underbrace{\dot{W}_{cv}}_{=0} + \dot{m} \]
\[ \underbrace{\dot{W}}_{=0} + \dot{m} \]

\[ \settowidth{\mylen}{$\dot{W}_{cv}$}
   \makebox[\mylen]{$\underbrace{\dot{W}_{cv}}_{=0}$}
   + \dot{m}
\]

\end{document}

Above I've set the \underbrace part in a box of fixed (this-is-what-I-want) width. The \makebox[\mylen] construction will automatically centre its contents.

You could do the same with the construction \underbrace{\dot{W}}_{=0}, but there would be an overlap with the \underbrace and the operator.

  • The last example has the correct spacing because \makebox makes an ordinary atom. See my answer and you'll see that it's not necessary, as the brace endings just use a very small space. You're focusing on the position of “m”, but the problem is the space between “+” and “m”. – egreg Jan 19 '15 at 18:53
  • 1
    @egreg: Good point. I'll keep my answer as an unnecessary alternative. :-| – Werner Jan 19 '15 at 19:49
4

Here are two ways to circumvent:

  1. Put the \underbrace in a box of the correct size. (This appears to be Werner's approach)

  2. Stack the underbrace under the argument, while ignoring the width of the underbrace. The \renewcommand\useanchowidth{T} is a stackengine macro that sets the mode of \useanchorwidth to "true", F (false) being the alternative. It tells the package that when creating a stack, the overall width of the stack should not be driven by the lateral dimension of the total stack, but instead dictated solely by the width of the "anchor" (which is the stack element that sits on the text baseline). In this case, that means that the \underbrace will not affect the width of the overall stack, and only the width of \dot{W}_{cv} will be allowed to dictate the total width of the stack. See example at end of post.

Here is the MWE:

\documentclass{article}
\usepackage{stackengine}
\stackMath
\usepackage{calc}
\begin{document}
\[ \dot{W}_{cv} + \dot{m} \]
\[ \makebox[\widthof{$\dot{W}_{cv}$}]{$\underbrace{\dot{W}_{cv}}_{=0}$} + \dot{m} \]
\renewcommand\useanchorwidth{T}
\[\stackunder[0pt]{\dot{W}_{cv}}{\underbrace{}_{=0}} + \dot{m}\]
\fboxsep=-\fboxrule
\[\fbox{\stackunder[0pt]{\dot{W}_{cv}}{\underbrace{}_{=\textrm{a long underset}}}} + \dot{m}\]
\end{document}

enter image description here

Here is an extreme demonstration of \useanchorwidth{T}. An \fbox has been placed around the stack.

enter image description here

  • Thank you, +1! Can you explain what the \useanchorwidth macro does (and why you chose T)? – darthbith Jan 19 '15 at 22:20
  • @darthbith I have provided an explanatory revision to my answer. – Steven B. Segletes Jan 19 '15 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.