Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

6 Answers 6

up vote 13 down vote accepted

I'd recommend the following:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\sqrt{\smash[b]{1\kern-2pt \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 smashes/obliterates only the stuff below the baseline. The \kern-2pt instruction removes the unnecessary whitespace otherwise inserted by the left-hand end of the underbrace, and the thinspace macro \, 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\kern-2pt \underbrace{44\cdots4\,}_\text{$n$ times}}}$
share|improve this answer
    
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
1  
@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
    
@Werner Thanks for the link :) –  Scott H. Jul 14 '12 at 2:23

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.

share|improve this answer

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:

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}
share|improve this answer

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.

share|improve this answer

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}
share|improve this answer
    
Yep. And it looks like someone has used \smash on the post that inspired this question too. –  Rahul Narain Jul 14 '12 at 2:13
3  
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

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.