Acabei de aprender LaTeX sozinho nos últimos três meses para minha tese. Agora preciso fazer uma apresentação e devo usar o beamer. Usei o Tikz na minha tese e gostaria de usá-lo novamente no beamer. Por mais que eu adorasse recortar e colar minha imagem tikz na apresentação, isso não parece funcionar. Aqui está um exemplo do que usei em minha tese.
\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}
Quero mostrar a progressão passo a passo de uma rota de colisão desde o início do algoritmo de inserção Robinson-Schensted até o final e faria isso usando vários slides, mas não entendo como os nós funcionam para isso ou mesmo que seja o que eu deveria estar usando. Como faço para criar essa "animação" de vários slides? Obrigado
Responder1
O poder do tikz é que você pode escrever macros facilmente para desenhar objetos regulares como tableaux. Eu tenho um código que escrevi para fazer algo semelhante. Em vez de desenhar quadros mais grossos, mudo a cor de fundo da célula, mas seria fácil adaptar meu código para criar quadros mais grossos, se preferir. A idéia principal é enterrar a maior parte do código do tableau dentro de uma macro para que você possa "escrever" cada tableau usando uma sintaxe natural e fácil de editar, como
\ShadedTableau{{1,1,2,2},{2,3,3,4},{3,4,6},{4,7}}
No seu caso de uso, você deseja sombrear determinadas células. Para atender a isso, permitimos um argumento opcional que é uma lista separada por vírgulas das coordenadas das células que queremos sombrear:
\ShadedTableau[(3,0),(2,-1),(1,-2)]{{1,1,2,2},{2,3,3,4},{3,4,6},{4,7}}
A \ShadedTableau
macro não é particularmente complicada: ela usa umtikz \foreach
loop para desenhar o quadro célula por célula, percorrendo as linhas e, em seguida, as entradas em cada linha do quadro, que são fornecidas como argumentos para \ShadedTableau
. (Existem alguns recursos extras nas macros abaixo que considero úteis.)
Usando isso com o beamer, seu MWE ficaria (pule para o quadro do beamer na primeira leitura, porque é onde estão seus quadros):
\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}
Isso produz a saída:
Como você perguntou sobre "animação de vários slides", no exemplo acima isso é feito simplesmente usando o \pause
comando, que "pausa" a apresentação até você clicar em uma tecla. Coisas mais complicadas são possíveis: veja o muito legívelprojetormanual para obter detalhes.
Responder2
Como é tarde demais para modificar o código do desenho, a maneira mais fácil é adicionar uma máscara sobre o desenho existente.
A estrutura básica é a seguinte:
\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}
PS. se você estiver usando o Adobe Reader e no modo de tela cheia, ele será reproduzido automaticamente para você.
\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}