# Underbrace under sqrt content

I am trying to use underbrace to clarify the arguments to a sqrt. However this causes the square root sign to reach all the way down to the bottom of the text under the brace(s), which is not what I want.

MWE:

\documentclass{article}
\usepackage{mathtools}

\begin{document}

$\sqrt{\underbrace{\frac{1}{\tau}\underbrace{\int_{\text{-}\infty}^{t}\underbrace{p_{X}^{\,2}\left(\xi\right)\cdot e^{\frac{\text{-}\left(t\text{-}\xi\right)}{\tau}}}_{\substack{\text{Expontial}\\\text{time-weighting}\\\text{of$p_{X}^{\,2}\left(\xi\right)$}}} \,\mathrm{d}\xi}_{\text{Exponential integration}}}_{\substack{\text{Exponential averaging}\\\text{= “Quasi mean-square”}}}}$

\end{document}

This results in something like this:

Does anyone know how I can force sqrt to reach only as low as its actual (mathematically speaking) argument?

-

I would recommend Mico's way; if you really want the surd, then here is a solution that takes all the vertical space it needs (not like in wh1t3's answer):

\documentclass{article}
\usepackage{mathtools}

\def\sqrtexplained#1{%
\begingroup
\sbox0{$#1$}
\def\underbrace##1_##2{##1}
\sbox2{$#1$}
\mathrlap{\sqrt{\phantom{\displaystyle#1}\kern\dimen0 }}
\hphantom{\sqrt{\vphantom{\displaystyle#1}}}
\endgroup
#1}

\begin{document}

$\sqrtexplained{% \underbrace{\frac{1}{\tau} \underbrace{\int_{-\infty}^{t} \underbrace{p_{X}^{2}(\xi)\cdot e^{\frac{-(t-\xi)}{\tau}}} _{\substack{\text{Exponential}\\ \text{time-weighting}\\ \text{of p_{X}^{2}(\xi)}} } \,\mathrm{d}\xi} _{\text{Exponential integration}}} _{\substack{\text{Exponential averaging}\\ =\text{Quasi mean-square}} } }$

\end{document}


I've also corrected the input errors you are making: \text{-} for a minus sign is wrong; \left and \right should be used only when they are really needed.

-
Works great, thanks! However, is it possible you forgot a \makeatother? –  Matthias Oct 25 '11 at 12:35
@Matthias Delete the \makeatletter, it's not needed (I already did in the answer). –  egreg Oct 25 '11 at 12:36

I would suggest that you not use the \sqrt{...} symbolism at all because it adds yet another horizontal bar to an expression that's already very busy-looking. Instead, I suggest you write something like:

\documentclass{article}
\usepackage{concrete,eulervm,mathtools}
\begin{document}
$\biggl(\, \underbrace{\frac{1}{\tau} \underbrace{\int\limits_{-\infty}^{t} \underbrace{p_{X}^{\,2} (\xi) \cdot e^{-(t-\xi)/\tau}} _{\substack{\text{Exponential time-}\\ \text{weighting of$p_{X}^{\,2}(\xi)$}}} \,d\xi} _{\text{Exponential integration}}} _{\substack{\text{Exponential averaging}\\ \text{$=$Quasi mean-square''}}} \,\biggr)^{1/2}$
\end{document}


-
I considered doing it like that, but because I use square root signs elsewhere in the document I would prefer to do so here as well for consistency. –  Matthias Oct 25 '11 at 12:14

You can use \smash and a \vphantom to make it work.

\documentclass{article}
\usepackage{mathtools}
\begin{document}

$\sqrt{\vphantom{\int_{\text{-}\infty}^{t}x}\smash{ \underbrace{ \frac{1}{\tau} \underbrace{ \int_{\text{-}\infty}^{t} \underbrace{ p_{X}^{\,2}\left(\xi\right)\cdot e^{\frac{\text{-}\left(t\text{-}\xi\right)}{\tau}} }_{\substack{\text{Expontial}\\\text{time-weighting}\\\text{of p_{X}^{\,2}\left(\xi\right)}}} \,\mathrm{d}\xi }_{\text{Exponential integration}} }_{\substack{\text{Exponential averaging}\\\text{= “Quasi mean-square”}}} }}$

\end{document}


The output looks like this:

I should note that this does not appear to work in inline math-mode. The size of the vphantom does not correctly reflect the integral sign then. Perhaps someone else can explain why this is the case, since I don't know.

Edit after @egreg's comment, an additional vphantom should be added, to ensure the displaymath gets the height of the braces as well. The modified code would look like this:

\documentclass{article}
\usepackage{mathtools}
\begin{document}

$\sqrt{\vphantom{\int_{\text{-}\infty}^{t}x}\smash{ \underbrace{ \frac{1}{\tau} \underbrace{ \int_{\text{-}\infty}^{t} \underbrace{ p_{X}^{\,2}\left(\xi\right)\cdot e^{\frac{\text{-}\left(t\text{-}\xi\right)}{\tau}} }_{\substack{\text{Expontial}\\\text{time-weighting}\\\text{of p_{X}^{\,2}\left(\xi\right)}}} \,\mathrm{d}\xi }_{\text{Exponential integration}} }_{\substack{\text{Exponential averaging}\\\text{= “Quasi mean-square”}}} }} \vphantom{\underbrace{ \frac{1}{\tau} \underbrace{ \int_{\text{-}\infty}^{t} \underbrace{ p_{X}^{\,2}\left(\xi\right)\cdot e^{\frac{\text{-}\left(t\text{-}\xi\right)}{\tau}} }_{\substack{\text{Expontial}\\\text{time-weighting}\\\text{of p_{X}^{\,2}\left(\xi\right)}}} \,\mathrm{d}\xi }_{\text{Exponential integration}} }_{\substack{\text{Exponential averaging}\\\text{= “Quasi mean-square”}}} }$

A long sentence after it to see if there are problems with overruning.

\end{document}


And its output like this:

-
An added \displaystyle ought to do it. –  Niel de Beaudrap Oct 25 '11 at 12:02
@NieldeBeaudrap yes, I gathered that from Stefan's answer as well. Why is this the case though? The actual integral in the formula is not set in displaystyle, so why would it need the additional height in the vphantom, when it clearly does not require it for the actual formula? –  Roelof Spijker Oct 25 '11 at 12:05
This doesn't give the formula its real vertical size; subsequent text will be superposed to it. –  egreg Oct 25 '11 at 12:21
@egreg you are absolutely right, added a vphantom to handle this. –  Roelof Spijker Oct 25 '11 at 12:24

Seems to be missing a tikz solution:

or with smaller text under the brace:

## Code:

\documentclass{article}
\usepackage{mathtools}
\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*{\VerticalOffset}{0.8ex}%
\newcommand*{\HorizontalOffset}{0.0em}%

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

\newcommand*{\MyEquation}{%
\tikzmark{StartBraceC}
\sqrt{%
\frac{1}{\tau}
\tikzmark{StartBraceB}
\int_{\text{-}\infty}^{t}
\tikzmark{StartBraceA}
p_{X}^{2}
\left(\xi\right)
\cdot e^{\frac{\text{-}\left(t\text{-}\xi\right)}{\tau}}
\tikzmark{EndBraceA}
\mathrm{d}\xi
\tikzmark{EndBraceB}
}
\hspace*{0.5em}\tikzmark{EndBraceC}
}
\begin{document}
$\MyEquation$
%
\InsertUnderBrace[draw=red,text=red]{StartBraceA}{EndBraceA}
{Exponential \\ time-weighting \\ of $p_{X}^{\,2}\left(\xi\right)$}
%
\InsertUnderBrace[draw=olive,text=olive][yshift=-1.5cm]{StartBraceB}{EndBraceB}
{Exponential \\ integration}
%
\InsertUnderBrace[draw=blue,text=blue][yshift=-2.5cm]{StartBraceC}{EndBraceC}
{Exponential averaging \\= Quasi mean-square"}
%
\vspace*{3.0cm}\par
\bigskip\noindent
or with smaller text
$\MyEquation$
%
\InsertUnderBrace[draw=red,text=red, font=\tiny]{StartBraceA}{EndBraceA}
{Exponential time-\\weighting of $p_{X}^{\,2}\left(\xi\right)$}
%
\InsertUnderBrace[draw=olive,text=olive, font=\tiny][yshift=-0.8cm]{StartBraceB}{EndBraceB}
{Exponential integration}
%
\InsertUnderBrace[draw=blue,text=blue, font=\tiny][yshift=-1.4cm]{StartBraceC}{EndBraceC}
{Exponential averaging = Quasi mean-square"}
\end{document}

-

If you would like to have nice looking braces then you can use the following brute force method.

\documentclass{article}
\usepackage{mathtools}
\usepackage{pstricks}
$$\sqrt{\frac{1}{\tau}\int_{-\infty}^{t} p_{X}^{2}(\xi)\cdot e^{t-\xi}d\xi}$$