Beamer 中的 TikZ 动画方程

Beamer 中的 TikZ 动画方程

我正在尝试重现这个例子使用 LaTeX Beamer 创建演示文稿 – 方程式和 tikz并且给定的代码会引发以下错误

包 pgfkeys 错误:我不知道密钥‘/tikz/na’。

LaTex 代码是

\documentclass[compress]{beamer}
\usetheme{Warsaw}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\tikzstyle{every picture}+=[remember picture]

\begin{document}

\begin{frame}
\frametitle{Test}


\begin{itemize}
\item Overall mean \tikz[na] \node[coordinate] (s1) {};
\end{itemize}

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

\begin{equation}
y_{ijk} = \tikz[baseline]{ \node[fill=blue!20,anchor=base,rounded corners=2pt]
  (d1) {$\mu$}; }
+ \tikz[baseline]{ \node[fill=red!20,anchor=base,rounded corners=2pt]
  (d2) {$r_{i}$}; }
+ \tikz[baseline]{ \node[fill=green!20,anchor=base,rounded corners=2pt]
  (d3) {$c_{j}$}; }
+ \tikz[baseline]{ \node[fill=yellow!20,anchor=base,rounded corners=2pt]
  (d4) {$t_{k}$}; }
+ \epsilon_{ijk}
\end{equation}

\begin{itemize}
\item Effect of row $i$ \tikz[na] \node[coordinate] (s2) {};
\item Effect of column $j$ \tikz[na] \node[coordinate] (s3) {};
\item Effect of treatment $k$ \tikz[na] \node[coordinate] (s4) {};
\end{itemize}

\begin{tikzpicture}[overlay]
\path[->] (s1) edge [bend left] (d1);
\path[->] (s2) edge [bend right] (d2);
\path[->] (s3) edge [out=0, in=-90] (d3);
\path[->] (s4) edge [out=0, in=-90] (d4);
\end{tikzpicture}

\end{frame}

\end{document}

另外,我的方程式不是动画。任何帮助修复此错误的帮助都将不胜感激。谢谢

答案1

如果你将其移至\tikzstyle{na} = [baseline=-.5ex]序言中,那么它会编译:

enter image description here

笔记:

动画片:

  • 由于您正在使用该类beamer,因此\pause可以使用宏来创建跨多张幻灯片的动画效果:

    \begin{tikzpicture}[overlay]                  \pause
        \path[->] (s1) edge [bend left] (d1);     \pause
        \path[->] (s2) edge [bend right] (d2);    \pause
        \path[->] (s3) edge [out=0, in=-90] (d3); \pause
        \path[->] (s4) edge [out=0, in=-90] (d4); \pause
    \end{tikzpicture}
    

通过这个改变和两次编译,您应该得到一份 6 页的文档,我认为它能满足您的要求。

enter image description here


代码:

\documentclass[compress]{beamer}
\usetheme{Warsaw}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [baseline=-.5ex]

\begin{document}

\begin{frame}
\frametitle{Test}


\begin{itemize}
\item Overall mean \tikz[na] \node[coordinate] (s1) {};
\end{itemize}


\begin{equation}
y_{ijk} = \tikz[baseline]{ \node[fill=blue!20,anchor=base,rounded corners=2pt]
  (d1) {$\mu$}; }
+ \tikz[baseline]{ \node[fill=red!20,anchor=base,rounded corners=2pt]
  (d2) {$r_{i}$}; }
+ \tikz[baseline]{ \node[fill=green!20,anchor=base,rounded corners=2pt]
  (d3) {$c_{j}$}; }
+ \tikz[baseline]{ \node[fill=yellow!20,anchor=base,rounded corners=2pt]
  (d4) {$t_{k}$}; }
+ \epsilon_{ijk}
\end{equation}

\begin{itemize}
\item Effect of row $i$ \tikz[na] \node[coordinate] (s2) {};
\item Effect of column $j$ \tikz[na] \node[coordinate] (s3) {};
\item Effect of treatment $k$ \tikz[na] \node[coordinate] (s4) {};
\end{itemize}

\begin{tikzpicture}[overlay]
\path[->] (s1) edge [bend left] (d1);
\path[->] (s2) edge [bend right] (d2);
\path[->] (s3) edge [out=0, in=-90] (d3);
\path[->] (s4) edge [out=0, in=-90] (d4);
\end{tikzpicture}

\end{frame}

\end{document}

答案2

这应该是@Peter Grill 关于动画的解决方案的补充。可以使用<1->如下 MWE 中的内容:

\documentclass[compress]{beamer}
\usetheme{Warsaw}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [baseline=-.5ex]

\begin{document}

\begin{frame}
\frametitle{Test}


\begin{itemize}
\item<2-> Overall mean \tikz[na] \node[coordinate] (s1) {};
\item<1->[]{%
\begin{equation}
y_{ijk} = \tikz[baseline]{ \node[fill=blue!20,anchor=base,rounded corners=2pt]
  (d1) {$\mu$}; }
+ \tikz[baseline]{ \node[fill=red!20,anchor=base,rounded corners=2pt]
  (d2) {$r_{i}$}; }
+ \tikz[baseline]{ \node[fill=green!20,anchor=base,rounded corners=2pt]
  (d3) {$c_{j}$}; }
+ \tikz[baseline]{ \node[fill=yellow!20,anchor=base,rounded corners=2pt]
  (d4) {$t_{k}$}; }
+ \epsilon_{ijk}
\end{equation}}%

\item<3-> Effect of row $i$ \tikz[na] \node[coordinate] (s2) {};
\item<4-> Effect of column $j$ \tikz[na] \node[coordinate] (s3) {};
\item<5-> Effect of treatment $k$ \tikz[na] \node[coordinate] (s4) {};
\end{itemize}


\begin{tikzpicture}[overlay]
\path<2->[->] (s1) edge [bend left] (d1);
\path<3->[->] (s2) edge [bend right] (d2);
\path<4->[->] (s3) edge [out=0, in=-90] (d3);
\path<5->[->] (s4) edge [out=0, in=-90] (d4);
\end{tikzpicture}

\end{frame}
\end{document}

enter image description here

相关内容