[Tex/LaTex] Underline number in two parts; math mode

bracesmath-mode

I'm trying to underbrace a binary numeral as follow:

  10111101
  '--''---'
    B   D

in order to show the binary-hexadecimal correspondence, but using twice the underbrace command:

\underbrace{1011}_B\underbrace{1101}_D

I get, obviously, two different "words":

  1011 1101
  '--' '---'
    B    D

How can I solve the issue?

Best Answer

\underbrace is defined infontmath.ltx` (part of LaTeX kernel for math stuff) as follows (shortened):

\def\underbrace#1{\mathop{...}\limits}

The construct is defined as math operator (\mathop). This way the lower limit can easily be specified as subscript. But TeX will add a thin space between two \mathop atoms.

This space can be removed by adding a negative thin space \!. Or the whole underbrace construct can be put into curly braces (subformula). Then it becomes an ordinary math atom (\mathord), where TeX will not add spaces inbetween.

The following example shows the differences between the two methods:

\documentclass{article}

\begin{document}
\[
  a
  \underbrace{1011}_B
  \!
  \underbrace{1101}_D
  b
\]
\[
  a
  {\underbrace{1011}_B}
  {\underbrace{1101}_D}
  b
\]
\end{document}

Result

Related Question