我正在尝试使用 TikZ 标记 Beamer 幻灯片上的方程式。这是我的代码:
\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}
问题是它会生成两张幻灯片,一张包含两个参考文献,另一张仅包含第一个参考文献。
另一个问题是,最后一个参考“投资组合差异”是红色的(实际文本),我可以将其更改为黑色吗?
答案1
我认为期望的结果是:
为了实现这一点,需要的代码是:
\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}
从您的 MWE 来看,箭头放置错误,因为您的na
样式只定义了位置baseline=.5ex
,但在下一张图片中没有被记住。您remember picture
还应该对其他两个锚点使用t1
和t2
。
如果您正在寻找两个框架,则只需更改:
\begin{tikzpicture}[remember picture,overlay]
\path[-stealth] (n1) edge [bend left] (t1);
\path[-stealth] (n2) edge [out=0, in=-90] (t2);
\end{tikzpicture}
进入:
\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}
请记住,您应该编译两次才能获得正确的结果。