我正在尝试使用 Tikz“动画”库创建 GIF。我想将 GIF 帧的快照创建为 latex PDF,然后使用在线工具将它们合并到 GIF 中。下面是我的代码。由于某种原因,我更改了“填充”属性的初始状态未显示,并且没有产生错误。关于如何修复该问题有什么建议吗?此外,我希望将每个快照放在单独的页面中,而不必每次想要拍摄快照时都更改自动机的坐标。我该怎么做?
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows.meta,calc,cd,animations}
\usetikzlibrary{patterns}
\usetikzlibrary{datavisualization}
\tikzset{
->, % makes the edges directed
>=stealth, % makes the arrow heads bold
node distance=3cm, % specifies the minimum distance between two nodes. Change if necessary.
every state/.style={thick, fill=gray!10}, % sets the properties for each ’state’ node
initial text=$ $, % sets the text that appears on the start arrow
}
\usepackage{animate}
\title{GIF Example}
\author{Mostafa Tavakkoli Anbarani}
\date{May 2023}
\begin{document}
\maketitle
\clearpage
\begin{tikzpicture}[node distance = 2cm, on grid,>={Stealth[inset=0pt,length=6pt,angle'=28,round]}]
\foreach \t in {0,2}{
\tikz [make snapshot of = \t]
\tikz [animate = {q1:fill = {0s = "red", 2s = "blue"}}]
\node[state, initial,fill] at (0,0-10*\t) (q1) {$q^1$};
\node[state] at (1,-2.5-10*\t) (q2) {$q^2$};
\node[state, right of=q2] (q3) {$q^3$};
\node[state, right of=q3] (q4) {$q^4$};
\node[state, right of=q4] (q5) {$q^5$};
\node[state,accepting] at (8,0-10*\t) (q6) {$q^6$};
\node[state] at (2,0-10*\t) (q7) {$q^7$};
\node[state, right of=q7] (q8) {$q^8$};
\node[state] at (6,0-10*\t) (q9) {$q^9$};
\node[state] at (1,2.5-10*\t) (q10) {$q^{10}$};
\node[state, right of=q10] (q11) {$q^{11}$};
\node[state, right of=q11] (q12) {$q^{12}$};
\node[state, right of=q12] (q13) {$q^{13}$};
\node[state,fill=red!20, densely dashed] at (2,-1.25-10*\t) (q14) {$q^{14}$};
\node[state,fill=red!20, densely dashed] at (4,-1.25-10*\t) (q15) {$q^{15}$};
\node[state,fill=red!20, densely dashed] at (2,1.25-10*\t) (q16) {$q^{16}$};
\node[state,fill=red!20, densely dashed] at (6,1.25-10*\t) (q17) {$q^{17}$};
\draw
(q1) edge[bend right] node [below left]{$e^1$} (q2)
(q2) edge node [below] {$e^2$} (q3)
(q3) edge node [below]{$e^3$} (q4)
(q4) edge node [below]{$e^4$} (q5)
(q5) edge[bend right] node [below right] {$e^5$} (q6)
(q1) edge node [above]{$e^6$} (q7)
(q7) edge node [above]{$e^7$} (q8)
(q8) edge node [above]{$e^8$} (q9)
(q9) edge node [above]{$e^9$} (q6)
(q1) edge[bend left] node [below left]{$e^{10}$} (q10)
(q10) edge node [above]{$e^{11}$} (q11)
(q11) edge node [above]{$e^{12}$} (q12)
(q12) edge node [above]{$e^{13}$} (q13)
(q13) edge[bend left] node [above right]{$e^{14}$} (q6)
(q2) edge[bend right, densely dashed] node [above left]{$e^{15}$} (q14)
(q14) edge[bend right, densely dashed] node [ right]{$e^{16}$} (q7)
(q4) edge[bend right, densely dashed] node [ right]{$e^{17}$} (q15)
(q15) edge[bend right, densely dashed] node [ right]{$e^{18}$} (q9)
(q12) edge[bend left=10, densely dashed] node [ above]{$e^{19}$} (q16)
(q16) edge[bend left=10, densely dashed] node [ above right]{$e^{20}$} (q9)
(q12) edge[bend left=10, densely dashed] node [ above right]{$e^{21}$} (q17)
(q17) edge[bend left, densely dashed] node [ above right]{$e^{22}$} (q9);
}
\end{tikzpicture}
\end{document}