18:56 - Wednesday, 23 April 2014

How To Paramerize A Tikz Chain Picture With List Of Nodes

I want to draw several tikz picture like these ones, but with different numbers of nodes in each row and arrows between the top and bottom row between different nodes.

e.g parallel chains and another parallel chain etc.

I want to create a macro, that I can reuse for every drawing. For example that is parametrized with 3 lists, 2 lists listing the nodes in the top and bottom rows e.g. [h_0,h_1,h_2], [h'_0,h'_1] and one that is a list of pairs [(h_0,h'_0), (h_2,h'_1)] – so the macro will draw the two chains and then draw an arrow between the node in the top row and the node in the bottom row for each of the given pairs.

I am quite a Latex beginner and I am unsure really where to start or what is a reasonable way in Latex to approach this sort of parametrization and iteration.

This is the markup I used to draw the above diagram:

documentclass{standalone}usepackage{tikz}usetikzlibrary{arrows,chains,scopes}begin{document}begin{tikzpicture} {[node distance=0.4cm,  start chain=going right,  every join/.style=->] node [on chain] (start) {$h_0$}; node [on chain,join] {$h_1$}; node [on chain,join] {$h_2$}; node [on chain,join] (C1) {$h_3$};  node [on chain, below=1cm of start] (start) {$h_0'$}; node [on chain,join] {$h_1'$}; node [on chain,join] {$h_2'$}; node [on chain,join] {$h_3'$};  node [on chain,join] (C2) {$h_4'$};  draw[thick,] (C1.south east)--(C2.north west);}end{tikzpicture}end{document}

With three foreach loops, this can be done fairly simple.

As the scopes library does not play nice with chains created inside a foreach loop (→