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 have 2 chains in different columns of a table. I need to shift the second chain in a such way that the {mv r0 <- a} would be below the {br a = 0 $end}, as it is depicted : right below the red line.

How to do it without inserting a fake node and adjusting its length?

Desired position
EDIT[as @Werner suggested]: Here is the code to reproduce the example. In the picture above, the right column is allready shifted by a graphical editor, originally they were aligned.

\newcommand*{\ld}[2]{ld\ #1\gets \$#2}
\newcommand*{\st}[2]{st\ #1\to \$#2}
\newcommand*{\add}[2]{add\ #1\gets #2}
\newcommand*{\mul}[2]{mul\ #1\gets #2}
\newcommand*{\mov}[2]{mv\ #1\gets #2}
\newcommand*{\inc}[1]{inc\ #1}
\newcommand*{\brz}[2]{br\ #1=0\ \$#2}

\begin{tikzpicture}
[-,auto,
up/.style={draw=none,above=.5cm},
down/.style={draw=none,below=.5cm},
long/.style={minimum height=2.5cm}]
\matrix [matrix,row sep=0.2cm,nodes={draw,font=\footnotesize},every even column/.style={text centered,text width=2.3cm}]
{
    \node (up1)[up]{};&&\node(up2)[up]{};&&\node (up3)[up]{};&&\node(up4)[up]{};&\\
&\begin{scope}
    [node distance=1mm, start chain=going below];
    \node [anchor=north, on chain] {$\inc a$};
    \node [on chain, long] {$\ld a a$};
    \node [on chain] {$\brz a{end}$};
    \node [on chain] {$\inc a$};
    \node [on chain, long] {$\ld a a$};
    \node [on chain] {$\brz a{end}$};
\end{scope}&
&\begin{scope}
    [node distance=1mm, start chain=going below];
    \node [anchor=north, on chain] {$\mov {r_0}a$};
    \node [on chain, long] {$\ld {r_1} {r_0}$};
    \node [on chain] {$\mul {r_1}{r_1*r_1}$};
    \node [on chain, long] {$\st {r_1} {r_0}$};
\end{scope}\\
    \node (down1)[down]{};&&\node (down2)[down]{};&&\node(down3)[down]{};&&\node(down4)[down]{};&\\
};
\begin{scope}
\draw (up1) to (down1);
\draw (up2) to (down2);
\draw (up3) to (down3);
\draw (up4) to (down4);
\end{scope}
\end{tikzpicture}
share|improve this question

migrated from stackoverflow.com Jun 1 '12 at 20:42

This question came from our site for professional and enthusiast programmers.

    
How does it work? Are these sites connected in some way? Why I don't logged in there if it is so? –  Necto Jun 1 '12 at 13:47
    
@Necto: Don't worry about it. Site moderators will move this for you. It would help though if you could include that generated the above output. That way community members can tackle the problem without trying to recreate it first. –  Werner Jun 1 '12 at 16:21
    
Your question was migrated here from another stackexchange site. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Martin Scharrer Jun 1 '12 at 20:49
add comment

2 Answers

up vote 1 down vote accepted

The at option combined with a named chain gives a solution: first chain is named ch; first node of second chain is north anchored at north of fourth node of first chain (ch-4.north).

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}

\newcommand*{\ld}[2]{ld\ #1\gets \$#2}
\newcommand*{\st}[2]{st\ #1\to \$#2}
\newcommand*{\add}[2]{add\ #1\gets #2}
\newcommand*{\mul}[2]{mul\ #1\gets #2}
\newcommand*{\mov}[2]{mv\ #1\gets #2}
\newcommand*{\inc}[1]{inc\ #1}
\newcommand*{\brz}[2]{br\ #1=0\ \$#2}

\begin{tikzpicture}
[-,auto,
up/.style={draw=none,above=.5cm},
down/.style={draw=none,below=.5cm},
long/.style={minimum height=2.5cm}]
\matrix [matrix,row sep=0.2cm,nodes={draw,font=\footnotesize},every even column/.style={text centered,text width=2.3cm}]
{
    \node (up1)[up]{};&&\node(up2)[up]{};&&\node (up3)[up]{};&&\node(up4)[up]{};&\\
&\begin{scope}
    [node distance=1mm, start chain=ch going below];
    \node [on chain] {$\inc a$};
    \node [on chain, long] {$\ld a a$};
    \node [on chain] {$\brz a{end}$};
    \node [on chain] {$\inc a$};
    \node [on chain, long] {$\ld a a$};
    \node [on chain] {$\brz a{end}$};
\end{scope}&
&\begin{scope}
    [node distance=1mm, start chain=going below];
    \node [on chain,anchor=north,at={(ch-4.north)}] {$\mov {r_0}a$};
    \node [on chain, long] {$\ld {r_1} {r_0}$};
    \node [on chain] {$\mul {r_1}{r_1*r_1}$};
    \node [on chain, long] {$\st {r_1} {r_0}$};
\end{scope}\\
    \node (down1)[down]{};&&\node (down2)[down]{};&&\node(down3)[down]{};&&\node(down4)[down]{};&\\
};
\begin{scope}
\draw (up1) to (down1);
\draw (up2) to (down2);
\draw (up3) to (down3);
\draw (up4) to (down4);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thank you. I didn't think, that "at" can work in such complicated manner. (sorry for confusion) –  Necto Jun 2 '12 at 9:45
    
In fact, this solution works only because each cell of the matrix is (re)positioned after its contents is computed. Outside of a matrix, the two chains are superimposed. –  Paul Gaborit Jun 2 '12 at 23:01
add comment

You can use matrix of nodes key to remove the additional \node declarations in the matrix cells. Also you can anchor the scope such that it is handled from that declared point lastly you can always shift your node around with a cm={a,b,c,d,(coord1,coord2} to scale with the [xnew;ynew] = [a,c;b,d]*[x;y] + [coord1;coord2] transformation matrix.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcommand*{\ld}[2]{ld\ #1\gets \$#2}
\newcommand*{\st}[2]{st\ #1\to \$#2}
\newcommand*{\add}[2]{add\ #1\gets #2}
\newcommand*{\mul}[2]{mul\ #1\gets #2}
\newcommand*{\mov}[2]{mv\ #1\gets #2}
\newcommand*{\inc}[1]{inc\ #1}
\newcommand*{\brz}[2]{br\ #1=0\ \$#2}
\begin{document}
\begin{tikzpicture}
[-,auto,
up/.style={draw=none,above=.5cm},
down/.style={draw=none,below=.5cm},
long/.style={minimum height=2.5cm}]
\matrix [row sep=0.2cm,nodes={draw,font=\footnotesize},every even column/.style={text centered,text width=2.3cm}]
{
    \node (up1)[up]{};&&\node(up2)[up]{};&&\node (up3)[up]{};&&\node(up4)[up]{};&\\
&\begin{scope}
    [node distance=1mm, start chain=going below];
    \node [anchor=north, on chain] {$\inc a$};
    \node [on chain, long] {$\ld a a$};
    \node [on chain] {$\brz a{end}$};
    \node [on chain] (inca) {$\inc a$};
    \node [on chain, long] {$\ld a a$};
    \node [on chain] {$\brz a{end}$};
\end{scope}&
&\begin{scope}[anchor=north west,cm={1,0,0,1,(inca.north east)},
    node distance=1mm, start chain=going below];
    \node [anchor=north, on chain] {$\mov {r_0}a$};
    \node [on chain, long] {$\ld {r_1} {r_0}$};
    \node [on chain] {$\mul {r_1}{r_1*r_1}$};
    \node [on chain, long] {$\st {r_1} {r_0}$};
\end{scope}\\
    \node (down1)[down]{};&&\node (down2)[down]{};&&\node(down3)[down]{};&&\node(down4)[down]{};&\\
};
\begin{scope}
\draw (up1) to (down1);
\draw (up2) to (down2);
\draw (up3) to (down3);
\draw (up4) to (down4);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
I'm sorry for the mess. I've mixed the answers. –  Necto Jun 2 '12 at 9:46
    
A'm aware of "matrix of nodes" but I could not make it work with chains. –  Necto Jun 2 '12 at 9:54
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.