8

I'm working on an animation of "Odd Magic Square" with Loubere Method.

But I can't hold the number "2" with dashed outline square on the two slides! How to? enter image description here

The code:

    \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}
7

You can play with the overlay specification of only. See the code below.

\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}

enter image description here

  • Many Thanks! Could you please explain the usage of .(a dot) ? – xaero Nov 1 '18 at 10:53
  • 1
    @xaero . in overlay specification denotes the current overlay number – samcarter_is_at_topanswers.xyz Nov 1 '18 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.