7

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?

6

\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

6

I'd recommend using tikzmark:

enter image description here

The parameters passed to \InsertUnderBrace are:

  • [#1] tikz draw options,

  • [#2] tikz brace options,

  • {#3} name of left \tikzmark,

  • {#4} name of right \tikzmark,

  • {#5} text to be placed under the brace.

Notes:

  • This does require two runs. First one to determine the locations, and the second to do the drawing.

  • This uses the \InsertUnderBrace from Asymmetric overbrace.

Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

% Tweak these as necessary
\newcommand*{\BraceAmplitude}{0.4em}%
\newcommand*{\BraceAspect}{0.5}% 
\newcommand*{\VerticalOffset}{0.4ex}%  
\newcommand*{\HorizontalOffset}{0.0em}% 


\NewDocumentCommand{\InsertUnderBrace}{%
    O{} % #1 = draw options
    O{} % #2 = optional brace options
    m   % #3 = left tikzmark
    m   % #4 = right tikzmark
    m   % #5 = text to place underbrace
}{%
    \begin{tikzpicture}[overlay,remember picture]
\draw [decoration={brace, amplitude=\BraceAmplitude, aspect=\BraceAspect, #2}, decorate, thick, draw=blue, text=black, #1]
        ($(#4)+(\HorizontalOffset,-\VerticalOffset)$) -- 
        ($(#3)+(-\HorizontalOffset,-\VerticalOffset)$)
        node [below=\VerticalOffset, midway] {#5};
    \end{tikzpicture}%
}%


\begin{document}
$\tikzmark{Left Mark} 1011 \tikzmark{Middle Mark} 1101 \tikzmark{Right Mark}$ 
\InsertUnderBrace[blue]{Left Mark}{Middle Mark}{B}%
\InsertUnderBrace[red]{Middle Mark}{Right Mark}{D}%
\end{document}

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.