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.

Getting a strange error where any path from a certain node starts in the incorrect place. The red paths are identical in code. The image on the left is what I expect, but the image on the right is what I'm getting. Any ideas what's causing this?

enter image description here

Right picture code (cropped the picture heavily, so there is a lot not shown):

\documentclass{article}

\usepackage{tikz}
\pagestyle{empty}

\begin{document}

%\input{../tikz-setup.tex}
\usetikzlibrary{shapes, arrows, calc, positioning}

% Define block styles
\tikzstyle{state}   = [ rounded rectangle, 
                        draw, 
                        text centered, 
                        minimum height=3em 
                      ]
\tikzstyle{test}    = [ diamond, 
                        draw, 
                        shape aspect=2, 
                        inner sep = 0pt,
                        text width = 7em,
                        text centered
                      ]
\tikzstyle{action}  = [ rectangle, draw,
                        text width=8em,
                        inner sep = 5pt, 
                        minimum height=5em
                      ]
\tikzstyle{data}    = [ trapezium, 
                        draw, 
                        trapezium left angle=60, 
                        trapezium right angle=120pt,
                        minimum height = 6em, 
                        text width = 5em
                       ]
\tikzstyle{line}    = [ draw, -triangle 45 ]


\begin{tikzpicture}[align = flush center, font = \small]
    % Place nodes
    \matrix [row sep = 1.2em] (mtrx)
    {
    \node [state] (a) {Lorem ipsum}; \\

    \node [test] (b) { dolor sit amet, con}; \\

    \node [test] (c) {sectetur adipiscing elit. In bibendu}; \\

    \node [test] (d) {m ante laoreet ante semper convallis. Pellentesque habi}; \\

    \node [action] (e) {tant morbi tristique senectus et netus et malesuada fames ac turpis eg}; \\

    \node [test] (f) {estas. Pellentesque vitae dia}; &    
    \node [test] (g) {m magna. Pellent}; \\

    \node [test] (h) {esque placerat sa}; \\

    \node [action] (i) {pien sed nisl faucibus tempor. Nullam nec quam nulla, se}; &
    \node [action] (j) {d pulvinar lacus. Aenean sit amet tellus erat, non temp}; &
    \node [action] (k) {or justo. Phasellus ege}; \\

    \node [test] (l) {stas iaculis nisi vel ve}; &
    \node [test] (m) {stibulum.Mauris id fa}; \\

    \node [state] (n) {cilisis massa. C}; &
    \node [state] (o) {urabitur feugiat v}; \\

    & 
    &
    \node [state, yshift=-2em] (p) {estibulum convallis \\ . Nulla dictum tinc}; \\
    };

    % Draw edges
    \path [line] (a) -- (b);

    \path [line] (b.east) -- node [above,very near start] {Yes} +(8.5,0) |- ( $(k)!0.85!(p)$ );
    \path [line] (b.south) -- node [right] {No} (c);

    \path [line] (c.south) -- node [right] {Yes} (d);    
    \path [line] (c.east) -| node [above,very near start] {No} (g);

    \path [line] (d.south) -- node [right] {Yes} (e);
    \path [line] (d.west) -- node [above] {No}  +(-1,0) |- coordinate[midway] (e) (f);

    \path [line, red] (e) -- (f);    
    \path [line] (g) -- node [right] {Yes} (j);

    \path [line] (k) -- (p);
\end{tikzpicture}

\end{document}

Left picture code:

\documentclass{article}

\usepackage{tikz}
\begin{document}
\pagestyle{empty}

\usetikzlibrary{shapes, arrows, calc, positioning}

% Define block styles
\tikzstyle{state}   = [ rounded rectangle, draw, 
                        text centered, 
                        minimum height=3em 
                      ]
\tikzstyle{test}    = [ diamond, 
                        draw, 
                        shape aspect=2, 
                        inner sep = 0pt,
                        text width = 7em,
                        text centered
                      ]
\tikzstyle{action}  = [ rectangle, draw,
                        text width=8em,
                        inner sep = 5pt, 
                        minimum height=5em
                      ]

\tikzstyle{line}    = [ draw, -triangle 45 ]

\begin{tikzpicture}[align = flush center, font = \small]
    % Place nodes
    \matrix[ row sep=1.2em] (mtrx) 
    {
    \node [test] (f) {fLorem ipsum dolor sit amet}; \\

    \node [test] (h) {hLorem ipsum dolo}; \\

    \node [action] (i) {iLorem ipsum dolor sit amet, consectetur adipiscing elit.}; \\

    \node [test] (l) {lLorem ipsum dolor};\\
    };

    \path [line,red] (i) -- (l);
    \path [line] (h.west) -- node [above] {No}  +(-1,0) |- coordinate[midway] (i) (l);
\end{tikzpicture}


\end{document}

Don't really understand how I'm getting this error.

share|improve this question
    
This isn't abundantly clear if you're just looking at the pictures, but the red path in the right picture is actually over the last turn of the black path. –  blitzvergnugen Sep 6 '12 at 22:12

1 Answer 1

up vote 3 down vote accepted

Don't use the same name (in your MWE, e) for different nodes or coordinates!

Look at this code:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  % first example
  \node (a) at (0,0) {A};
  \node (b) at (1,1) {B};
  \draw (a) -- node [pos=.5] (c) {C} (b);
  \draw[blue] (a) to[bend left] (b); 

  % second example
  \node (d) at (2,0) {D};
  \node (e) at (3,1) {E};
  \draw (d) -- node [pos=.5] (d) {D} (e);
  \draw[red] (d) to[bend left] (e); 
\end{tikzpicture}
\end{document}

enter image description here

The first example uses three different names, so the blue line is right.

The second example uses the d name for two different nodes, so the red line is not right.

Edit:

When you write:

\draw (a) -- coordinate[midway] (m) (b);

you trigger two different actions:

  1. The drawing of the path between a and b as with \draw (a) -- (b);

  2. The definition of the coordinate m along the path between a and b in the midway position (midway is equivalent to pos=.5).

share|improve this answer
    
So is the coordinate[midway] (e) (f); redefining e? –  blitzvergnugen Sep 7 '12 at 16:38
    
@blitzvergnugen coordinate[midway] (e) redefines e. (f) is just the end of the path. –  Paul Gaborit Sep 7 '12 at 16:49
    
So I'm confused now. I thought that coordinate[midway] (e) (f) would return the coordinates of the midway point between e & f. I know that midway is just a macro for pos=0.5, but I don't understand how that gets me in the middle of 2 points. Is it giving me the halfway point between (in your example) a and b since those are the start and end points of the path? –  blitzvergnugen Sep 7 '12 at 17:41
    
@blitzvergnugen I edited my answer to give a few details. –  Paul Gaborit Sep 7 '12 at 17:55

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.