Make sure that the following packages are loaded:
\usepackage{tikz}
\usetikzlibrary{tikzmark,arrows,calc}
and add the following definition to your preamble:
\newcommand\sidecomment[5][0.3,0.1]%
{\begin{tikzpicture}[remember picture,overlay]
\draw[-stealth',thick]
($({pic cs:#4}|-{pic cs:#2})+(#1)$)
.. controls +(1,0) and +(1,0) ..
node[right,align=left]{#5}
($({pic cs:#4}|-{pic cs:#3})+(#1)$);
\end{tikzpicture}%
}
Add marks at the end of the lines where you want the arrow to start and end using
\tikzmark{name of mark}
Then you can use the command
\sidecomment[offset]{<start mark>}{<end mark>}{<alignment mark>}{<text>}
to draw an arrow from start mark
to end mark
labeled with text
. To align start and end of the arrow vertically, use the rightmost of these two marks additionally as alignment mark
. offset
is an optional argument that allows to shift start and end of the arrow by the same amount; it is a pair of numbers x,y
that gives the x- and y-offset in cm. The default is 0.3,0.1
, i.e., \sidecomment{a}{b}{c}{d}
is the same as \sidecomment[0.3,0.1]{a}{b}{c}{d}
, which means that the arrow starts and ends 3mm right of the mark and 1mm above the baseline.
Note that you have to run LaTeX twice to get the positions right.
The following document was typeset with the code below it.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark,arrows,calc}
\usepackage{amsmath}
\newcommand\sidecomment[5][0.3,0.1]%
{\begin{tikzpicture}[remember picture,overlay]
\draw[-stealth',thick]
($({pic cs:#4}|-{pic cs:#2})+(#1)$)
.. controls +(1,0) and +(1,0) ..
node[right,align=left]{#5}
($({pic cs:#4}|-{pic cs:#3})+(#1)$);
\end{tikzpicture}%
}
\begin{document}
\begin{align*}
\beta_1^*
&= \frac{\sum_{i=1}^n(x_i^*-\hat x^*)y_i^*}{\sum_{i=1}^n(x_i^*-\hat x^*)^2}\tikzmark{a}\\
&= \frac{\sum_{i=1}^n(w_2x_i-w_2\hat x)w_1y_i}{\sum_{i=1}^n(w_2x_i-w_2\hat x)^2}\tikzmark{b}
\end{align*}
\sidecomment{a}{b}{b}{since $y_i^*=w_1y_i$\\and $x_i*=w_2x_i$}
\end{document}