# Program Tikz in Beamer

The attached .Rnw-code produces two similar slides, but with different texts and different arrow positions. I wrote both slides manually, but because I need to produce hundreds of similar slides, I would prefer to write only one type-slide, and use variable-names that relate to the R-table to draw the slides. One slide per row in the R-table. How can this be done?

Update: Tom Bombadil gave a much better example (I replaced my original with it). It is correct, with the addition that the source of the numbers and arrow positions come from an R-script. Here is the modified version.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

% Here are the numbers and coordinates that should be different on each slide (one row per slide).
<<input, echo=FALSE>>=
#input.data <- rbind(c(1, 1234, 1965, 3, 4),
#c(2, 5678, 1974, 7, 4))
#colnames(input.data) <- c("SlideNr", "LeftNr", "RightNr", "ArrowPos1", "ArrowPos2")
@

\begin{frame}
\begin{tikzpicture}
\draw (0,0) rectangle (10,4);
\node[above right] at (0,0) {1234};
\node[above left] at (10,0) {1965};
\node[single arrow,shape border rotate=90,fill=white,below,draw] at (3,4) {1.};
\end{tikzpicture}
\end{frame}

\begin{frame}
\begin{tikzpicture}
\draw (0,0) rectangle (10,4);
\node[above right] at (0,0) {5678};
\node[above left] at (10,0) {1974};
\node[single arrow,shape border rotate=90,fill=white,below,draw] at (7,4) {2.};
\end{tikzpicture}
\end{frame}

\end{document}


How can one "link" a field in a table from R with a text or number in the Tikz?

Update 2. Thanks to Tom's response and comments I realized I can do the formatting in R instead. If I create this file (intext1.tex) in R (paste("\def\x{",variable,"}",sep="")):

\def\x{1234}
\def\z{3}


and intext2.tex

\def\x{4321}
\def\z{7}


...then I can do this in LaTex:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\foreach \n in {1,...,2} {
\input{intext\n.tex}
\begin{frame}
\begin{tikzpicture}
\draw (0,0) rectangle (10,4);
\node[above right] at (0,0) {\x};
\node[above left] at (10,0) {1965};
\node[single arrow,shape border rotate=90,fill=white,below,draw] at (\z,4) {1.};
\end{tikzpicture}
\end{frame}
}
\end{document}

-
It is not obvious where you plug in the data in your drawings. Could you add TeX comments to the relevant places, please? – krlmlr Oct 18 '12 at 22:56
Try to keep your code minimal please. Instead of a lot of stuff, boil it down to e.g. drawing a circle and some arrows at different positions. Remember, this site is not about solving your specific problem, but any future visitors problem which has the same underlaying cause. – Tom Bombadil Oct 18 '12 at 23:18
"You don't have to sign with your name since it automatically appears in the lower right corner of your post." "Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you." – Tom Bombadil Oct 18 '12 at 23:34
Is the given R output the only available, or can you influence it inside R? For instance, neither @ nor # are good ideas in LaTeX. Would it be possible to give it column wise, like e.g. ("SlideNr",1,2) ("LeftNr",1234,5678) and so on? Even bonusier´´ it would be if the colnames were just letters, no numbers or other stuff, then one could use them for defining commands from them. – Tom Bombadil Oct 19 '12 at 16:08
Yes, this is it. Got it. See my update 2. – Chris Oct 19 '12 at 20:58

Are you looking for something like this?

## Code

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\begin{frame}
\begin{tikzpicture}
\draw (0,0) rectangle (10,4);
\node[above right] at (0,0) {\only<1>{1234}\only<2>{5678}};
\node[above left] at (10,0) {\only<1>{1965}\only<2>{1974}};
\only<1>{\node[single arrow,shape border rotate=90,fill=white,below,draw] at (3,4) {1.};
}
\only<2>{\node[single arrow,shape border rotate=90,fill=white,below,draw] at (7,4) {2.};
}
\end{tikzpicture}
\end{frame}

\end{document}


-