Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to generate a picture that replicates itself and slowy fades out. For that i plan to use a foreach statement and redraw the picture to its rigth.

How can i use the foreach variable to position my replicated pictures.

Here is a minimal example that illustrates what i want. The remaining job in the minimal example is to somehow use \x to create the names for relative adressing the nodes during redraw.

\begin{tikzpicture}[
  item/.style={draw=black!#1, thick, text=black!#1, minimum width = 60},
  label/.style={text=black!#1, right},
  action/.style={black!#1, ->, thick},
  downfrom/.style={below = 0.5 of {#1.south}, anchor=north},
  rightfrom/.style={right = 0.5 of {#1.north east}, anchor=north west}
]

\foreach \x in {100}
{
    \node [item=\x]                     (first100) {first};
    \node [item=\x, downfrom=first100]  (second100) {second};
    \path[action=\x](first100) edge node [label=\x] {a} (second100.north);
}   

 \foreach \x in {67}
{
    \node [item=\x, rightfrom=first100] (first67) {first};
    \node [item=\x, downfrom=first67]   (second67) {second};
    \path[action=\x](first67) edge node [label=\x] {a} (second67.north);
}   

 \foreach \x in {34}
 {
    \node [item=\x, rightfrom=first67] (first34) {first};
    \node [item=\x, downfrom=first34]  (second34) {second};
    \path[action=\x](first34) edge node [label=\x] {a} (second34.north);
 }  

\end{tikzpicture}

What i want to write but i dont know how would look like this:

\begin{tikzpicture}[
  item/.style={draw=black!#1, thick, text=black!#1, minimum width = 60},
  label/.style={text=black!#1, right},
  action/.style={black!#1, ->, thick},
  downfrom/.style={below = 0.5 of {#1.south}, anchor=north},
  rightfrom/.style={right = 0.5 of {#1.north east}, anchor=north west}
]

\foreach \x in {100, 67, 34}
{
 \node ???
 \node ???
 \path ???
}   

\end{tikzpicture}
share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

Something like this?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[
  item/.style={draw=black!#1, thick, text=black!#1, minimum width = 60},
  label/.style={text=black!#1, right},
  action/.style={black!#1, ->, thick, draw},
  downfrom/.style={below = 0.5 of {#1.south}, anchor=north},
  rightfrom/.style={right = 0.5 of {#1.north east}, anchor=north west}
]

\path coordinate(last);
\foreach \x in {100,67,34}
{
  \node[item=\x, rightfrom=last, alias=last](first\x){first};
  \node[item=\x, downfrom=first\x](second\x){second};
  \path[action=\x](first\x) edge node [label=\x] {a} (second\x);
}    
\end{tikzpicture}

\end{document}
share|improve this answer
    
Exactly what i wanted. How does it work? i set an invisible path for the first item and then change the path alias to reflext what my next first node is,... is that about rigth? –  Johannes Feb 7 '13 at 17:53
    
yes. well, precisely, the alias does not refer to a path but to a coordinate/node, just like a name. –  Sašo Živanović Feb 7 '13 at 17:55
add comment

You can scope the drawing and shift it each time to the right.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
  item/.style={draw=black!#1, thick, text=black!#1, minimum width = 60},
  label/.style={text=black!#1, right},
  action/.style={black!#1, ->, thick},
  downfrom/.style={below = 0.5 of {#1.south}, anchor=north},
  rightfrom/.style={right = 0.5 of {#1.north east}, anchor=north west}
]

\foreach \x[count=\xi from 0] in {100,64,37}
{
\begin{scope}[shift={(3*\xi,0)}]
    \node [item=\x]                     (first\x) {first};
    \node [item=\x, downfrom=first\x]  (second\x) {second};
    \path[action=\x](first\x) edge node [label=\x] {a} (second\x.north);
\end{scope}
}   

\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
+1 ... This looks neat, but i dont want to use absolute positioning. Somehow i feel i could use something like \def to make me a list and use that for naming. –  Johannes Feb 7 '13 at 17:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.