如何将一个对象放在两张幻灯片上?

如何将一个对象放在两张幻灯片上?

我正在使用 Loubere 方法制作“奇数魔方”的动画。

但我无法在两张幻灯片上保留带有虚线轮廓的数字“2”!怎么办? 在此处输入图片描述

代码:

    \documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usetheme{default}
%\usepackage{listings}
\usepackage{tikz}

\begin{document}



\begin{frame}{$n$- magic matrix} % ================================================================
\begin{itemize}[<+->]
\item text1
\item text2
\item text3
\end{itemize}

\begin{onlyenv}<+->
\begin{tikzpicture}
\tikzstyle{normal}=[fill=yellow!80!red]
\tikzstyle{testing}=[fill=yellow!80!red, fill opacity=0.4, dashed]
\tikzstyle{redarrow}=[->, thick, red]

\foreach \x in {0,1,2}
    \foreach \y in {0,1,2} {
        \draw[normal] (\x, \y) rectangle +(1, 1);
    }
\fill[fill opacity=0.1, fill=white] (-1, 3) rectangle +(1, 1);
\only<+->{
    \node at (1.5, 2.5) {$1$};
}
\only<+>{
    \draw[testing] (2, 3) rectangle +(1, 1);
    \node at (2.5, 3.5) {$2$};
}
\only<+>{
    \draw[redarrow] (2.5, 3.5) --(2.5, 0.8);    
}
\only<.->{
    \node at (2.5, 0.5) {$2$};
}
\only<+>{
    \draw[testing] (3, 1) rectangle +(1, 1);
    \node at (3.5, 1.5) {$3$};
}
\only<+>{
    \draw[redarrow] (3.5, 1.5) --(0.8, 1.5);    
}
\only<.->{
    \node at (0.5, 1.5) {$3$};
}
\only<+>{
    %\draw[fill=white] (1, 2) rectangle +(1, 1);
    \draw[fill=red!80!black, fill opacity=0.4, draw=red, dashed] (1, 2) rectangle +(1, 1);
    \node at (1.8, 2.2) {$4$};
}
\only<+->{
    \node at (0.5, 0.5) {$4$};
}
\end{tikzpicture}
\end{onlyenv}
\end{frame}
\end{document}

答案1

你可以尝试一下 的覆盖规范only。请参阅下面的代码。

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usetheme{default}
%\usepackage{listings}
\usepackage{tikz}

\begin{document}



\begin{frame}{$n$- magic matrix} % ================================================================
\begin{itemize}[<+->]
\item text1
\item text2
\item text3
\end{itemize}

\begin{onlyenv}<+->
\begin{tikzpicture}
\tikzstyle{normal}=[fill=yellow!80!red]
\tikzstyle{testing}=[fill=yellow!80!red, fill opacity=0.4, dashed]
\tikzstyle{redarrow}=[->, thick, red]

\foreach \x in {0,1,2}
    \foreach \y in {0,1,2} {
        \draw[normal] (\x, \y) rectangle +(1, 1);
    }
\fill[fill opacity=0.1, fill=white] (-1, 3) rectangle +(1, 1);
\only<+->{
    \node at (1.5, 2.5) {$1$};
}
\only<.-+>{
    \draw[testing] (2, 3) rectangle +(1, 1);
    \node at (2.5, 3.5) {$2$};
}
\only<.>{
    \draw[redarrow] (2.5, 3.5) --(2.5, 0.8);    
}
\only<.->{
    \node at (2.5, 0.5) {$2$};
}
\only<+>{}
\only<.-+>{
    \draw[testing] (3, 1) rectangle +(1, 1);
    \node at (3.5, 1.5) {$3$};
}
\only<.>{
    \draw[redarrow] (3.5, 1.5) --(0.8, 1.5);    
}
\only<.->{
    \node at (0.5, 1.5) {$3$};
}
\only<+>{
    %\draw[fill=white] (1, 2) rectangle +(1, 1);
    \draw[fill=red!80!black, fill opacity=0.4, draw=red, dashed] (1, 2) rectangle +(1, 1);
    \node at (1.8, 2.2) {$4$};
}
\only<+->{
    \node at (0.5, 0.5) {$4$};
}
\end{tikzpicture}
\end{onlyenv}
\end{frame}
\end{document}

在此处输入图片描述

相关内容