![修复 beamer 中 \only-slides 之间的 tikzpicture 节点位置](https://linux22.com/image/464948/%E4%BF%AE%E5%A4%8D%20beamer%20%E4%B8%AD%20%5Conly-slides%20%E4%B9%8B%E9%97%B4%E7%9A%84%20tikzpicture%20%E8%8A%82%E7%82%B9%E4%BD%8D%E7%BD%AE.png)
我想在投影仪幻灯片上显示图表。但是,使用
\begin{frame}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm,semithick]
% Nodes
\node[draw,circle,fill=cyan!10] (v1) at (0, 0) {$-5$};
\node[draw,circle,fill=cyan!10] (t) at (2, 0) {$-1$};
% Edges
\only<1>{ \path (t) edge node {$1$} (v1);}
\only<2>{ \path (t) edge node {$1 / 2$} (v1);}
% Legend
\node[draw, rectangle, below] at (-1.5, -1) {
\begin{tabular}{@{}rcl@{}}
\only<1->{Some text & : & A \\}
\only<2->{More text & : & B \\
Even more & : & C}
\end{tabular}
};
\end{tikzpicture}
\end{frame}
导致节点在由此生成的两个幻灯片之间向东北方向稍微移动。我更希望节点位置在两个幻灯片之间固定,而图例略有变化。remember picture
向 tikzpicture 添加参数没有帮助。
答案1
\only
我不会使用 ,而是使用\visible
和visible on=
(后者来自overlay-beamer-styles
库)。这样,内容仍然出现在其他覆盖层上,只是不可见,从而避免跳转。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\usetikzlibrary{arrows}
\begin{document}
\begin{frame}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm,semithick]
% Nodes
\node[draw,circle,fill=cyan!10] (v1) at (0, 0) {$-5$};
\node[draw,circle,fill=cyan!10] (t) at (2, 0) {$-1$};
% Edges
\path[visible on=<1>] (t) edge node {$1$} (v1);
\path[visible on=<2>] (t) edge node {$1 / 2$} (v1);
% Legend
\node[draw, rectangle, below] at (-1.5, -1) {
\begin{tabular}{@{}rcl@{}}
\visible<1->{Some text & : & A \\}
\visible<2->{More text & : & B \\
Even more & : & C}
\end{tabular}
};
\end{tikzpicture}
\end{frame}
\end{document}