7

I want to keep the size of the square root unchanged without putting the underbrace outside

\sqrt{\underbrace{=A}{B}}

Paul Gessler
  • 29,607
Noix07
  • 451

3 Answers3

9

Smashing the radicand is not sufficient. Here's a working version:

\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum} % just for the example

\newcommand{\smashedsqrt}[2][]{%
  \vphantom{#2}%
  \sqrt[#1]{\smash[b]{#2}}%
}

\begin{document}

\lipsum*[3]
\[
\smashedsqrt{\underbrace{B}_{=A}}
\]
\lipsum*[3]
\[
\sqrt{\smash[b]{\underbrace{B}_{=A}}}
\]
\lipsum[3]

\end{document}

The second example shows the problem with the simple smashing.

enter image description here

egreg
  • 1,121,712
7

I suppose this is what you want:

enter image description here

Here is the exact code:

\sqrt{\smash[b]{{\underbrace{B}_{=A}}}}

However the square root symbol is wider than if there were no underbrace if the "B" part is too small. In such case one has to do some (limited) manual adjustment because the square root symbol must not be too close from the underbrace. All this is illustrated with the following code:

  \begin{align*}
  & \sqrt{\smash[b]{{\underbrace{B + C + D}_{=A}}}}\qquad \sqrt{B + C + D}\\[4ex]
  & \sqrt{B}\qquad \sqrt{\mskip-6mu \smash[b]{{\underbrace{B}_{=A}}}\mskip-6mu}
  \end{align*}

enter image description here

Moreover, as pointed by @egreg, smashing can cause a problem with vertical spacing with the following text, so one should add, as he did in his answer, a \vphantom of the unsmashed square root, hence the creation of macro in order to make typing less painful — and the code clearer.

Bernard
  • 271,350
  • 1
    In the image provided, the \sqrt symbol sure looks bigger than it needs to be with just the B (without the underbrace). – Peter Grill May 08 '14 at 17:53
  • 1
    The line below the one with the smashed box will be too near. – egreg May 08 '14 at 18:00
  • @egreg: I supposed it was used in a display formula, in which case it may be unimportant. But you're — strictly speaking onze should add a \vphantom. – Bernard May 08 '14 at 18:19
  • @petergrill: actually it does look bigger because what's over the underbrace is too small. The underbrace seems to have a minimal size, so that in such a case, one has to do some manual adjustment. – Bernard May 08 '14 at 18:24
  • As you see from my example, it is important. – egreg May 08 '14 at 18:25
5

Here is an adaptation of Typesetting 144...4 with "n times" under the 4's is easy, but what about \sqrt{144...4}?, and note that the size of the \sqrt symbol is not affected by the underbrace:

enter image description here

Note:

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

  • The \tikzmark is from Adding a large brace next to a body of text.

  • As this is a tikz solution, all the inherent drawing capabilities are available - shown here is just the color of the brace and the text, but many more options are available.

Code:

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

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

% Tweak these as necessary \newcommand{\BraceAmplitude}{0.25em}% \newcommand{\VerticalOffset}{0.4ex}%
\newcommand{\HorizontalOffset}{0.12em}% \newcommand{\SquareBraceVOffset}{-0.4ex}%

\newcommand*{\InsertUnderBrace}[4][]{% \begin{tikzpicture}[overlay,remember picture] \draw [decoration={brace,amplitude=\BraceAmplitude},decorate, thick,draw=blue,text=black,#1] ($(#3)+(\HorizontalOffset,-\VerticalOffset)$) -- ($(#2)+(-\HorizontalOffset,-\VerticalOffset)$) node [below=\VerticalOffset, midway] {#4}; \end{tikzpicture}% }%

\newcommand*{\InsertUnderSquareBrace}[4][]{% \begin{tikzpicture}[overlay,remember picture] \draw [text=black,line width=0.7pt, #1] ($(#3)+(\HorizontalOffset,\VerticalOffset+\SquareBraceVOffset)$) -- ($(#3)+(\HorizontalOffset,-\VerticalOffset+\SquareBraceVOffset)$) -- ($(#2)+(-\HorizontalOffset,-\VerticalOffset+\SquareBraceVOffset)$) node [below, midway] {#4} -- ($(#2)+(-\HorizontalOffset,\VerticalOffset+\SquareBraceVOffset)$); \end{tikzpicture}% }%

\begin{document} \lipsum[1] [ \sqrt{\tikzmark{StartBraceA}B\tikzmark{EndBraceA},} \hspace*{4.0em} \sqrt{\tikzmark{StartBraceB}B\tikzmark{EndBraceB},} ] \InsertUnderBrace[draw=red,text=blue]{StartBraceA}{EndBraceA}{$=A$} \InsertUnderSquareBrace[draw=red,text=blue]{StartBraceB}{EndBraceB}{$=A$}

\lipsum[2] \end{document}

Peter Grill
  • 223,288