[Tex/LaTex] Beamer TikZ generating two slides

beamertikz-pgf

I'm trying to label an equation I have on a Beamer slide with TikZ. Here's my code:

\begin{frame}
\frametitle{Power Utility Portfolio Choice}

\tikzstyle{na} = [baseline=-.5ex]

\begin{itemize}[<+-| alert@+>]
    \item Portfolio Return
        \tikz[na]\node [coordinate] (n1) {};
\end{itemize}

\begin{equation*}
\begin{aligned}
& \underset{\boldsymbol w_t}{\text{maximise}}
& & \tikz[baseline]{
        \node[fill=blue!20,anchor=base] (t1)
            {$\boldsymbol w_t \cdot \bar{\boldsymbol r}_t $};
    } + \frac{1 - \gamma}{2} 
    \tikz[baseline]{
            \node[fill=red!20,anchor=base] (t2)
            {$ \boldsymbol w_t \cdot (\Sigma_t\boldsymbol w_t) $};
    } \\
& \text{subject to}
& & \boldsymbol w_t \cdot \boldsymbol \iota = 1\\
&&& \boldsymbol w_t \ge 0
\end{aligned}
\end{equation*}

\begin{itemize}[<+-| alert@+>]
    \item Portfolio Variance
        \tikz[na]\node [coordinate] (n2) {};
\end{itemize}

\begin{tikzpicture}[overlay]
        \path[->]<1-> (n1) edge [bend left] (t1);
        \path[->]<2-> (n2) edge [out=0, in=-90] (t2);
\end{tikzpicture}

\end{frame}

The problem is it generates two slides, one with both references and another with just the first.

Another issue is the last reference "Portfolio variance" is in red (the actual text), can I change it to black?

Best Answer

I think the desired result was:

enter image description here

To obtain this the code needed is:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}
\frametitle{Power Utility Portfolio Choice}

\begin{itemize}
    \item Portfolio Return
        \tikz[remember picture, overlay, baseline=-.5ex]\node (n1) {};
\end{itemize}

\begin{equation*}
\begin{aligned}
& \underset{\boldsymbol w_t}{\text{maximise}}
& & \tikz[baseline,remember picture]{
        \node[fill=blue!20,anchor=base] (t1)
            {$\boldsymbol w_t \cdot \bar{\boldsymbol r}_t $};
    } + \frac{1 - \gamma}{2} 
    \tikz[baseline,remember picture]{
            \node[fill=red!20,anchor=base] (t2)
            {$ \boldsymbol w_t \cdot (\Sigma_t\boldsymbol w_t) $};
    } \\
& \text{subject to}
& & \boldsymbol w_t \cdot \boldsymbol \iota = 1\\
&&& \boldsymbol w_t \ge 0
\end{aligned}
\end{equation*}

\begin{itemize}
    \item Portfolio Variance
        \tikz[remember picture,overlay, baseline=-.5ex]\node (n2) {};
\end{itemize}

\begin{tikzpicture}[remember picture,overlay]
        \path[-stealth] (n1) edge [bend left] (t1);
        \path[-stealth] (n2) edge [out=0, in=-90] (t2);
\end{tikzpicture}

\end{frame}

\end{document}

From your MWE, arrows were placed wrong because your na style just defined the position baseline=.5ex but was not remembered in the next picture. You should use remember picture also for the other two anchors t1 and t2.

In case you are looking for two frames, you have just to change:

\begin{tikzpicture}[remember picture,overlay]
        \path[-stealth] (n1) edge [bend left] (t1);
        \path[-stealth] (n2) edge [out=0, in=-90] (t2);
\end{tikzpicture}

into:

\begin{tikzpicture}[remember picture,overlay]
        \path[-stealth]<1-> (n1) edge [bend left] (t1);
        \path[-stealth]<2-> (n2) edge [out=0, in=-90] (t2);
\end{tikzpicture}

Remember that you should compile twice to get the right result.