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'm trying to find the best way of dynamically positioning the blue path. The important part is its position relative to b and c. I currently am using \path [line,blue] let \p1=(a.south), \p2=(c) in (h.south) |- +(2,-0.5) |- (\x2, \y1) -- (c.north); for the blue path, but it really doesn't give me much dynamic control.

I've thought about trying add a couple of let points and taking the middle of their x-values, but I can't seem to figure out how to do that. It would look something like: \path [line,blue] let \p1=(a.south), \p2=(c), \p3=(b.east), \p4=(c.west) in (h.south) -| +( AAA , -0.5) |- (\x2, \y1) -- (c.north); where AAA would be something like ($(\x3 !0.25! \x4)$) or (\x3 + \x4)*0.75 but that really seems like a kludgy way of doing it.

So, what's the best way to draw this path so that it will scale dynamically??

Also open to any suggestions on improving the red path. path

\documentclass{article}

\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\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{line}    = [ draw, -triangle 45 ]

\begin{center}
\begin{tikzpicture}[align = flush center, font = \small]
    % Place nodes
    \matrix [column sep = 3em, row sep = 1.2em] (mtrx)
    {

    \node [state] (a) {a};\\

    \node [action] (b) {b}; &
    \node [test] (c) {c}; \\

    \node [action] (d) {d}; &
    &
    \node [action] (e) {e}; \\

    \node [action] (f) {f}; &
    &
    \node [action] (g) {g}; \\

    \node [action] (h) {h}; \\
    };

    % Draw edges         
    \path [line, red] (c.west) -- ($(b.east)!0.75!(c.west)$) |- ($(e.south)!0.5!(g.north)$);
   %\path [line, red] let \p1=(e), \p2=(f), \p3=(c.west), \p4=(b.east) in (c.west) -- ($(\x3, \y3)!0.25!(\x4, \y3)$) |- ($(\x1, \y1)!0.5!(\x1, \y2)$); %alt

    \path [line,blue] let \p1=(a.south), \p2=(c) in (h.south) |- +(2,-0.5)  |- (\x2, \y1) -- (c.north);

\end{tikzpicture}
\end{center}
\end{document}
share|improve this question
    
try this \path (b.east) -- (b.east-|c.west)coordinate[pos=0.25](xx) ; \path[line,blue] (h.south) |- ($(h.south east) +(0,-0.5)$) -| (xx) -- (a.south-|xx) -|(c.north); –  rpapa Sep 10 '12 at 19:53

1 Answer 1

up vote 2 down vote accepted

try this

\documentclass{article}
\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\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{line}    = [ draw, -triangle 45 ]

\begin{center}
\begin{tikzpicture}[align = flush center, font = \small]
    % Place nodes
    \matrix [column sep =5em, row sep = 2em] (mtrx)
    {

    \node [state] (a) {a};\\

    \node [action] (b) {b}; &
    \node [test] (c) {c}; \\

    \node [action] (d) {d}; &
    &
    \node [action] (e) {e}; \\

    \node [action] (f) {f}; &
    &
    \node [action] (g) {g}; \\

    \node [action] (h) {h}; \\
    };

    % Draw edges         
    \path [line, red] (c.west) -- ($(b.east)!0.75!(c.west)$) |- ($(e.south)!0.5!(g.north)$);


  \path (b.east) -- (b.east-|c.west)coordinate[pos=0.25](xx) ;
  \path[line,blue] (h.south) |- ($(h.south east) +(0,-0.5)$) -| (xx) -- (a.south-|xx) -|(c.north);

\end{tikzpicture}
\end{center}
\end{document}

la ligne

\path (b.east) -- (b.east-|c.west)coordinate[pos=0.25](xx) ;

permet de créer un point intermédiaire entre les deux noeuds (b) et (c). Il ne reste plus qu'à relier les points


The line

\path (b.east) -- (b.east-|c.west)coordinate[pos=0.25](xx) ;

creates an intermediate point between the two nodes (b) and (c). The remaining step is to connect the dots.

share|improve this answer
2  
It is good practice to add a bit of an explanation when posting an answer. Please be a little more explicit and make your answer more than a comment. –  canaaerus Sep 10 '12 at 20:12
    
@percusse :Thank you for the translation, I generally translate, but I was pressed for time merci pour la traduction, en général je traduis, mais la j'étais pris par le temps –  rpapa Sep 11 '12 at 19:11
    
@rpapa Je vous en prie. –  percusse Sep 11 '12 at 19:35

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.