Typesetting 144…4 with “n times” under the 4's is easy, but what about \sqrt{144…4}?

Inspired by this question on the math StackExchange, suppose you want to typeset the square root of the number 144…4, that is, 1 followed by n 4’s. If you write $\sqrt{1\underbrace{44\ldots4}_{n\ \text{times}}}$, as in the current version of the question, you get a huge radical sign that reaches down to match the “n times” text below the number. Is there an elegant way to typeset this so that the radical sign looks like it would with $\sqrt{144\ldots4}$, but also keeping the underset text in the right place?

Solutions Collecting From Web of "Typesetting 144…4 with “n times” under the 4's is easy, but what about \sqrt{144…4}?"

I’d recommend the following:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\sqrt{\smash[b]{1\! \underbrace{44\cdots4\,}_\text{$n$ times}}}$
\end{document}

enter image description here

Note that it’s syntactically cleaner to place $n$ times inside a \text macro. The \smash[b] command “hides” the stuff below the baseline from TeX, inducing it not to make the lower end of square-root symbol plunge down to far. The \! instruction removes the unnecessary whitespace otherwise inserted by the left-hand end of the underbrace, while \, serves to avoid a clash between the right-hand end of the underbrace and the final 4. Finally, and I realize that some will disagree with me, I think it’s better to use \cdots than \ldots in this case.

Addendum: This MWE was meant to produce an image of a single formula in which the “root” of the square-root symbol doesn’t plunge down unnecessarily far. If this formula were part of some longer running text, a problem would immediately arise: the following line of text and math — and, depending on the depth of the underbrace contents, even the line after that — will run smack over the underbrace material. As @egreg notes in his comment and as @Werner shows in his answer, to keep this from happening the formula should be augmented to contain a \vphantom outside the square-root that has the exact same depth as the formula would have if \smash weren’t being used. This may be done, e.g., as follows:

$\vphantom{\underbrace{4}_{n}} \sqrt{\smash[b]{1\! \underbrace{44\cdots4\,}_\text{$n$ times}}}$

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\[
  \sqrt{144\ldots4\smash{\llap{$\underbrace{\phantom{44\ldots4}}_{\text{$n$ times}}$}}}
    \vphantom{1\underbrace{44\ldots4}_{\text{$n$ times}}}
\]
\end{document}

The “entire” number is typeset, followed by a left overlap that is \smashed. The additional (almost duplicate) \vphantom is to ensure that the vertical height of the expression matches that of what is visible, otherwise the underbrace might stretch into text below it.

amsmath provides \text.

The standard overkill TikZ solution using the infamous \tikzmark works great for situations such as this:

enter image description here

Note:

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

References:

  • This is a tweaked version of the solution used in Using \underbrace with table columns, and Overbrace in amsmath align environment.
  • The brace is adapted from adding a large brace next to a body of text

Code:

\documentclass{article}
\usepackage{amsmath}
\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*{\VerticalOffset}{0.4ex}%  
\newcommand*{\HorizontalOffset}{0.0em}% 
\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)+(0,\VerticalOffset+\SquareBraceVOffset)$) -- 
            ($(#3)+(\HorizontalOffset,-\VerticalOffset+\SquareBraceVOffset)$) -- 
            ($(#2)+(-\HorizontalOffset,-\VerticalOffset+\SquareBraceVOffset)$)
            node [below, midway] {#4} --
            ($(#2)+(0,\VerticalOffset+\SquareBraceVOffset)$);
    \end{tikzpicture}%
}%

\begin{document}
\[
    \sqrt{1\tikzmark{StartBraceA}44\cdots4\tikzmark{EndBraceA}\,}
    \quad
    \sqrt{1\tikzmark{StartBraceB}44\cdots4\tikzmark{EndBraceB}\,}
\]

\InsertUnderBrace[draw=red,text=blue]{StartBraceA}{EndBraceA}{$n$ times}

\InsertUnderSquareBrace[draw=red,text=blue]{StartBraceB}{EndBraceB}{$n$ times}
\end{document}

The command \raisebox has two optional argument: the height and depth of the resulting box. You want your expression with underbrace to have zero depth and the natural height, so this works:

$\sqrt{1
\raisebox{0pt}[\height][0pt]{$\underbrace{44\ldots4}_{n\ \text{times}}$}}$

enter image description here

The \smash command in the Scott H.’s answer does almost the same.

Would something like this work?

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\sqrt{\smash{1\underbrace{44\ldots4}_{n\ \text{times}}}\vphantom{1}}$
\end{document}

The answers are great but this time I couldn’t stop myself to write up an answer though there are 4 answers already. The detail I’m kind of obsessed is the underbraces and their fat appearance when the argument is short. Thanks to the mathtools package this issue is solved to a great extent and moreover you can also use less intrusive \underbracket. Here are two examples:

\documentclass{article}
\usepackage{amsmath,mathtools}
\begin{document}
\[\sqrt{\smash[b]{1\kern-2pt\underbracket[0.5pt][1pt]{4\cdots 44}_\text{$n$ many}}}\]

\[\sqrt{\smash[b]{1\kern-2pt\underbrace{4\cdots 44}_\text{$n$ many}}}\]
\end{document}

enter image description here

Notice the brace arms are smoothly rendered instead of a rather crude concatenation.