# 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?

I'd recommend the following:

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


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}}}$

• Mico, how are you getting the nice graphic to upload? Whenever I try to upload and crop the generated pdf, I get a tiny picture that scales into a pixelated mess. – Scott H. Jul 14 '12 at 2:15
• @ScottH. - I crop the image file very tightly and then save it as a png file at 300 dpi. – Mico Jul 14 '12 at 2:18
• In which program? – Scott H. Jul 14 '12 at 2:19
• @ScottH.: Perhaps some of the links in How can I upload an image to be included in a question or answer? might be helpful. I do a regular screen capture (in Windows, PrntScr), then paste in Paint, and crop the image to the desired size, then save as a PNG and upload. – Werner Jul 14 '12 at 2:22
• A \vphantom{\underbrace{4}_{n}} outside the argument of \sqrt is necessary to tell TeX what vertical space is occupied. – egreg Jul 14 '12 at 7:27

\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:

## Note:

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

## 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}}$}}$


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

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}


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

• n many sounds odd. I otherwise agree that a bracket looks nicer than a brace here. – Bruno Le Floch Jul 14 '12 at 15:12
• @BrunoLeFloch Ehm, that's probably my bad English interfering. – percusse Jul 14 '12 at 17:49

Would something like this work?

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

• Yep. And it looks like someone has used \smash on the post that inspired this question too. – Rahul Jul 14 '12 at 2:13
• A good solution. However, you do not need \vphantom: $\sqrt{1\smash{\underbrace{44\ldots4}_{n\ \text{times}}}}$ – Boris Jul 14 '12 at 2:14
• Ahh, good point. It didn't occur to me to leave the one outside! – Scott H. Jul 14 '12 at 2:19