[Tex/LaTex] Equation with vertical arrow

arrowsequations

How I get this equation with vertical arrows that help describe some of its terms?

\begin{equation*}
0 \leq F = \underbrace{\sum\limits_{i=1}^{n}(y_i - \overline{y})^2}_{(n-1)s_y^2} 
- 2b \underbrace{\sum\limits_{i=1}^{n}(x_i - \overline{x})(y_i - \overline{y})}_{(n-1)s_{xy} = (n-1)rs_xs_y}
+b^2 \underbrace{\sum\limits_{i=1}^{n}(x_i - \overline{x})^2}_{(n-1)s_x^2}
\end{equation*}

enter image description here

Best Answer

The command \uparrow makes an extensible arrow.

\documentclass{article}
\usepackage{mathtools}

\newcommand\vertarrowbox[3][6ex]{%
  \begin{array}[t]{@{}c@{}} #2 \\
  \left\uparrow\vcenter{\hrule height #1}\right.\kern-\nulldelimiterspace\\
  \makebox[0pt]{\scriptsize#3}
  \end{array}%
}
\begin{document}

\begin{equation*}
0 \leq F = 
{\underbrace{\sum_{i=1}^{n}(y_i-\bar{y})^2}_{(n-1)s_y^2}}
-\vertarrowbox{2b}{text}
{\underbrace{{}\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})}_{(n-1)s_{xy} = (n-1)rs_xs_y}}
+\vertarrowbox{b^2}{More text}
{\underbrace{{}\sum_{i=1}^{n}(x_i-\bar{x})^2}_{(n-1)s_x^2}}
\end{equation*}

\begin{equation*}
0 \leq F = 
\sum_{i=1}^{n}(y_i-\bar{y})^2
-2b
\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})
+b^2
\sum_{i=1}^{n}(x_i-\bar{x})^2
\end{equation*}

\end{document} 

The strange braces can be easily explained: \underbrace makes an Op atom, which conflicts with the spacing of binary operations, so it's best to brace it. However, if \sum is preceded by an ordinary symbol, a thin space should appear, which is produced by the empty subformula {} inside \underbrace when necessary.

The second display shows the standard spacing without \underbrace and the arrows, just for checking the spaces are the same.

The \vertarrowbox has an optional argument for the desired height of the arrow, default 6ex. Call it as \vertarrowbox[12ex]{<symbol>}{<text>} if you want to double the height (its size should depend on context).

enter image description here

Related Question