在過去的三個月裡,我剛剛為了我的論文自學了 LaTeX。現在我需要做一個演示,我應該使用投影機。我在論文中使用了 Tikz,並且想在 Beamer 中再次使用它。儘管我很想將 tikzpicture 剪下並貼上到簡報中,但這似乎不起作用。這是我在論文中使用的範例。
\begin{tikzpicture}
\matrix (m) [
matrix of math nodes,
nodes in empty cells,
minimum width=width("8"),
] {
1 & 1 & 2 & 2 & & & & & & & 1 & 1 & 2 & 2 & & & & & & 1 & 1 & 2 & 2 & \leftarrow & 3 & 1 & & 1 & 1 & 2 & 2 & 3 & \leftarrow & 1 & \\
2 & 3 & 3 & 4 & & & & & & & 2 & 3 & 3 & 4 & & & & & & 2 & 3 & 3 & 4 & & & & & 2 & 3 & 3 & 4 & & & & \\
3 & 4 & 6 & & & & & & & = & 3 & 4 & 6 & & & & & & = & 3 & 4 & 6 & & & & & = & 3 & 4 & 6 & & & & & = \\
4 & 7 & & & \leftarrow & 5 & \leftarrow & 3 & 1 & & 4 & 5 & & & & & & & & 4 & 5 & & & & & & & 4 & 5 & & & & & & \\
& & & & & & & & & & & & & & \leftarrow & 7 & \leftarrow 3 & 1 & & 7 & & & & & & & & 7 & & & & & & & \\
} ;
\draw (m-1-1.north west) rectangle (m-1-2.south east);
\draw (m-2-4.north west) rectangle (m-2-4.south east);
\draw[Red!,line width=2] (m-1-4.north west) rectangle (m-1-4.south east);
\draw (m-1-1.north west) rectangle (m-4-1.south east);
\draw (m-1-3.north west) rectangle (m-1-3.south east);
\draw (m-3-3.north west) rectangle (m-3-3.south east);
\draw[Red!,line width=2] (m-2-3.north west) rectangle (m-2-3.south east);
\draw (m-3-1.north west) rectangle (m-3-1.south east);
\draw (m-4-2.north west) rectangle (m-4-2.south east);
\draw[Red!,line width=2] (m-3-2.north west) rectangle (m-3-2.south east);
\draw (m-1-11.north west) rectangle (m-1-11.south east);
\draw (m-1-12.north west) rectangle (m-1-12.south east);
\draw (m-1-13.north west) rectangle (m-1-13.south east);
\draw (m-2-14.north west) rectangle (m-2-14.south east);
\draw (m-2-12.north west) rectangle (m-2-12.south east);
\draw[Red!,line width=2] (m-1-14.north west) rectangle (m-1-14.south east);
\draw (m-2-11.north west) rectangle (m-2-11.south east);
\draw (m-3-13.north west) rectangle (m-3-13.south east);
\draw[Red!,line width=2] (m-2-13.north west) rectangle (m-2-13.south east);
\draw (m-3-11.north west) rectangle (m-3-11.south east);
\draw[Red!,line width=2] (m-3-12.north west) rectangle (m-3-12.south east);
\draw (m-4-11.north west) rectangle (m-4-11.south east);
\draw[Red!,line width=2] (m-4-12.north west) rectangle (m-4-12.south east);
\draw (m-1-21.north west) rectangle (m-1-21.south east);
\draw (m-1-22.north west) rectangle (m-1-22.south east);
\draw (m-1-20.north west) rectangle (m-1-20.south east);
\draw (m-2-20.north west) rectangle (m-2-20.south east);
\draw (m-2-21.north west) rectangle (m-2-21.south east);
\draw (m-2-23.north west) rectangle (m-2-23.south east);
\draw[Red!,line width=2] (m-1-23.north west) rectangle (m-1-23.south east);
\draw (m-3-22.north west) rectangle (m-3-22.south east);
\draw[Red!,line width=2] (m-2-22.north west) rectangle (m-2-22.south east);
\draw (m-3-20.north west) rectangle (m-3-20.south east);
\draw[Red!,line width=2] (m-3-21.north west) rectangle (m-3-21.south east);
\draw (m-4-20.north west) rectangle (m-4-20.south east);
\draw[Red!,line width=2] (m-4-21.north west) rectangle (m-4-21.south east);
\draw[Red!,line width=2] (m-5-20.north west) rectangle (m-5-20.south east);
\draw (m-1-28.north west) rectangle (m-1-31.south east);
\draw[Orange!,line width=2] (m-1-32.north west) rectangle (m-1-32.south east);
\draw (m-1-28.north west) rectangle (m-4-28.south east);
\draw (m-1-30.north west) rectangle (m-3-30.south east);
\draw (m-2-29.north west) rectangle (m-2-31.south east);
\draw (m-4-28.north west) rectangle (m-5-28.south east);
\draw (m-3-28.north west) rectangle (m-3-28.south east);
\draw (m-4-29.north west) rectangle (m-4-29.south east);
\end{tikzpicture}
我想展示從 Robinson-Schensted 插入演算法的開始到結束的碰撞路線的逐步進展,我將使用多張幻燈片來完成此操作,但我不明白節點是如何工作的或即使它是我應該使用的。我該如何創建這個多幻燈片“動畫”?謝謝
答案1
tikz 的強大之處在於您可以輕鬆編寫巨集來繪製常規物件(例如舞台效果)。我寫了一些程式碼來做類似的事情。我不是繪製更厚的框架,而是更改單元格的背景顏色,但如果您願意,可以輕鬆調整我的程式碼來製作更厚的框架。主要想法是將大部分畫面程式碼隱藏在巨集中,以便您可以使用自然且易於編輯的語法「編寫」每個畫面,例如
\ShadedTableau{{1,1,2,2},{2,3,3,4},{3,4,6},{4,7}}
在您的用例中,您希望能夠對某些單元格進行著色。為了滿足這一點,我們允許一個可選參數,它是我們想要著色的單元格的座標的逗號分隔清單:
\ShadedTableau[(3,0),(2,-1),(1,-2)]{{1,1,2,2},{2,3,3,4},{3,4,6},{4,7}}
該\ShadedTableau
巨集並不是特別複雜:它使用蒂克茲 \foreach
循環逐個單元格繪製表格,循環遍歷表格的行,然後循環每行中的條目,這些條目作為 的參數給出\ShadedTableau
。 (下面的巨集中有一些額外的功能,我發現它們很有用。)
將其與投影機一起使用,您的 MWE 看起來會像這樣(第一次閱讀時跳到投影機框架,因為那是您的畫面所在的位置):
\documentclass{beamer}
\usepackage{xcolor}
\usepackage{tikz}
% tikz macro for drawing tableaux with optionally shaded nodes.
% \ShadedTableau{{1,2,3,4},{5,6,7},{8,9}} -> 1234/567/89
% \ShadedTableau[(1,-1),(2,-1),(2,0),(3,0),(4,0)]{{1,2,3,4},{5,6,7},{8,9}}
\newdimen\shadedBaseline\shadedBaseline=-4mm
\newcount\tableauRow\newcount\tableauCol
\newcommand\ShadedTableau[2][\relax]{%
\begin{tikzpicture}[scale=0.4,draw/.append style={thick,black},baseline=\shadedBaseline]
\ifx\relax#1\relax%
\else % shade the boxes in #1
\foreach\bx in {#1} { \filldraw[blue!20]\bx+(-.5,-.5)rectangle++(.5,.5); }
\fi
\tableauRow=0
\foreach \Row in {#2} {
\tableauCol=1
\foreach\k in \Row {
\draw(\the\tableauCol,\the\tableauRow)+(-.5,-.5)rectangle++(.5,.5);
\draw(\the\tableauCol,\the\tableauRow)node{\k};
\global\advance\tableauCol by 1
}
\global\advance\tableauRow by -1
}
\end{tikzpicture}%
}
\begin{document}
\begin{frame}{Bumping}
\ShadedTableau[(4,0),(3,-1),(2,-2)]{{1,1,2,2},{2,3,3,4},{3,4,6},{4,7}}
\quad
\pause $\overset{\longleftarrow 5\longleftarrow 3\ 1}{=}$\quad
\ShadedTableau[(4,0),(3,-1),(2,-2),(2,-3)]{{1,1,2,2},{2,3,3,4},{3,4,6},{4,5}}
\qquad
\pause $\overset{\longleftarrow 7\longleftarrow 3\ 1}{=}$\quad
\ShadedTableau[(4,0),(3,-1),(2,-2),(2,-3),(1,-4)]{{1,1,2,2},{2,3,3,4},{3,4,6},{4,5},{7}}
\end{frame}
\end{document}
這會產生輸出:
由於您詢問了“多幻燈片動畫”,在上面的範例中,只需使用該\pause
命令即可實現此目的,該命令會“暫停”演示文稿,直到您單擊某個鍵。更複雜的事情是可能的:參見非常可讀的投影儀手冊了解詳細資訊。
答案2
由於修改繪圖程式碼為時已晚,最簡單的方法是在現有繪圖上新增遮罩。
基本架構如下:
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\foreach\i in{1,...,30}{
\begin{frame}
your picture
\tikz[remember picture,overlay]{
\filldraw[fill=white](current page.west)++(\i/2,-1)rectangle+(12,4)--+(0,0);
}
\transreplace
\transduration{0}
\end{frame}
}
\end{document}
附言。如果您使用 Adobe reader 並處於全螢幕模式,它將自動為您播放。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\def\tempamp{&}
\catcode`\&13 \let&\tempamp
\foreach\i in{1,...,30}{
\begin{frame}
\centering\begin{tikzpicture}[transform canvas={scale=.6}]
\matrix (m) [
matrix of math nodes,
nodes in empty cells,
minimum width=width("8"),
] {
1 & 1 & 2 & 2 & & & & & & & 1 & 1 & 2 & 2 & & & & & & 1 & 1 & 2 & 2 & \leftarrow & 3 & 1 & & 1 & 1 & 2 & 2 & 3 & \leftarrow & 1 & \\
2 & 3 & 3 & 4 & & & & & & & 2 & 3 & 3 & 4 & & & & & & 2 & 3 & 3 & 4 & & & & & 2 & 3 & 3 & 4 & & & & \\
3 & 4 & 6 & & & & & & & = & 3 & 4 & 6 & & & & & & = & 3 & 4 & 6 & & & & & = & 3 & 4 & 6 & & & & & = \\
4 & 7 & & & \leftarrow & 5 & \leftarrow & 3 & 1 & & 4 & 5 & & & & & & & & 4 & 5 & & & & & & & 4 & 5 & & & & & & \\
& & & & & & & & & & & & & & \leftarrow & 7 & \leftarrow 3 & 1 & & 7 & & & & & & & & 7 & & & & & & & \\
} ;
\draw (m-1-1.north west) rectangle (m-1-2.south east);
\draw (m-2-4.north west) rectangle (m-2-4.south east);
\draw[red!,line width=2] (m-1-4.north west) rectangle (m-1-4.south east);
\draw (m-1-1.north west) rectangle (m-4-1.south east);
\draw (m-1-3.north west) rectangle (m-1-3.south east);
\draw (m-3-3.north west) rectangle (m-3-3.south east);
\draw[red!,line width=2] (m-2-3.north west) rectangle (m-2-3.south east);
\draw (m-3-1.north west) rectangle (m-3-1.south east);
\draw (m-4-2.north west) rectangle (m-4-2.south east);
\draw[red!,line width=2] (m-3-2.north west) rectangle (m-3-2.south east);
\draw (m-1-11.north west) rectangle (m-1-11.south east);
\draw (m-1-12.north west) rectangle (m-1-12.south east);
\draw (m-1-13.north west) rectangle (m-1-13.south east);
\draw (m-2-14.north west) rectangle (m-2-14.south east);
\draw (m-2-12.north west) rectangle (m-2-12.south east);
\draw[red!,line width=2] (m-1-14.north west) rectangle (m-1-14.south east);
\draw (m-2-11.north west) rectangle (m-2-11.south east);
\draw (m-3-13.north west) rectangle (m-3-13.south east);
\draw[red!,line width=2] (m-2-13.north west) rectangle (m-2-13.south east);
\draw (m-3-11.north west) rectangle (m-3-11.south east);
\draw[red!,line width=2] (m-3-12.north west) rectangle (m-3-12.south east);
\draw (m-4-11.north west) rectangle (m-4-11.south east);
\draw[red!,line width=2] (m-4-12.north west) rectangle (m-4-12.south east);
\draw (m-1-21.north west) rectangle (m-1-21.south east);
\draw (m-1-22.north west) rectangle (m-1-22.south east);
\draw (m-1-20.north west) rectangle (m-1-20.south east);
\draw (m-2-20.north west) rectangle (m-2-20.south east);
\draw (m-2-21.north west) rectangle (m-2-21.south east);
\draw (m-2-23.north west) rectangle (m-2-23.south east);
\draw[red!,line width=2] (m-1-23.north west) rectangle (m-1-23.south east);
\draw (m-3-22.north west) rectangle (m-3-22.south east);
\draw[red!,line width=2] (m-2-22.north west) rectangle (m-2-22.south east);
\draw (m-3-20.north west) rectangle (m-3-20.south east);
\draw[red!,line width=2] (m-3-21.north west) rectangle (m-3-21.south east);
\draw (m-4-20.north west) rectangle (m-4-20.south east);
\draw[red!,line width=2] (m-4-21.north west) rectangle (m-4-21.south east);
\draw[red!,line width=2] (m-5-20.north west) rectangle (m-5-20.south east);
\draw (m-1-28.north west) rectangle (m-1-31.south east);
\draw[orange!,line width=2] (m-1-32.north west) rectangle (m-1-32.south east);
\draw (m-1-28.north west) rectangle (m-4-28.south east);
\draw (m-1-30.north west) rectangle (m-3-30.south east);
\draw (m-2-29.north west) rectangle (m-2-31.south east);
\draw (m-4-28.north west) rectangle (m-5-28.south east);
\draw (m-3-28.north west) rectangle (m-3-28.south east);
\draw (m-4-29.north west) rectangle (m-4-29.south east);
\end{tikzpicture}
\tikz[remember picture,overlay]{
\filldraw[fill=white](current page.west)++(\i/2,-1)rectangle+(12,4)--+(0,0);
}
\transreplace
\transduration{0}
\end{frame}
}
\end{document}