3

I am currently making a flowchart to describe the dependencies of modules in an algorithm. There are several branches and these reconnect at some point. Because my algorithm is still changing, the flowchart will be updated.

I would like to have the node (Target_02) reconnecting the branches to depend on x-coordinate of the pre-split node (Origin) and the y-coordinate of two final nodes in each branch by taking the lowest of y-values between node (Operation_01cc) and node (Target_01a).

Or: how do I compare coordinates between two nodes?

enter image description here

\documentclass[border={5pt 5pt 5pt 5pt}]{standalone}

\usepackage{tikz}

\usetikzlibrary{arrows.meta}
\tikzset{%
>={Latex[width=2mm,length=2mm]},
% Specifications for style of nodes:
base/.style = {rectangle, rounded corners, draw=black,
    minimum width=4cm, minimum height=1cm,
    text centered, font=\sffamily},
Table/.style = {base, bottom color=yellow!70, top color=white},
TableTarget/.style = {base, bottom color=green!75!black!70, top color=white},
AnOperation/.style = {base, bottom color=gray!70, top color=white},
finalTarget/.style = {base, bottom color=blue!70, top color=white, draw=blue},
}
\begin{document}    
% Drawing part, node distance is 1.5 cm and every node
% is prefilled with white backgroun
\begin{tikzpicture}[node distance=1.5cm,
every node/.style={fill=white, font=\sffamily}, align=center, scale=0.8]

\node (Origin)          [Table]{00};                                                        

%%%%%%%%%%%%%%%%%%%%%%%%
%%% PREPPING SOURCE. %%%
%%%%%%%%%%%%%%%%%%%%%%%%

\node (Operation_00b)   [AnOperation, above of=Origin] {};                          
\node(Source_00b)       [Table, left of=Operation_00b, xshift=-3 cm] {};    
\node (Operation_00a)   [AnOperation, above of=Operation_00b] {};   
\node(Source_00a)       [Table, left of=Operation_00a, xshift=-3 cm] {};                                
\node (Source_Table)    [Table, above of=Operation_00a] {};                 

\draw[->]               (Source_Table)              -- (Operation_00a);   
\draw[->]               (Source_00a)    -- (Operation_00a);                         
\draw[->]               (Operation_00a)         -- (Operation_00b);
\draw[->]               (Source_00b)        -- (Operation_00b);                         
\draw[->]               (Operation_00b)         -- (Origin);                                


%%%%%%%%%%%%%%%%%%%
%%% BRANCH 01a. %%%
%%%%%%%%%%%%%%%%%%%

\node (Operation_01aa)  [AnOperation, below of=Origin, xshift=-9cm] {};
\node (Source_01aa)     [Table, left of=Operation_01aa, xshift=-3cm] {};    
\node (Operation_01ab)  [AnOperation, below of=Operation_01aa] {};                                                                      
\node (Source_01ab)     [Table, left of=Operation_01ab, xshift = -3cm] {};  
\node (Operation_00ac)  [AnOperation, below of=Operation_01ab] {};
\node (Source_01ac)     [Table, left of=Operation_00ac, xshift = -3cm]  {};
\node (Target_01a)      [TableTarget, below of=Operation_00ac]      {01ac}; 

\draw[->]               (Source_01aa) -- (Operation_01aa);                                      
\draw[->]               (Origin) -| (Operation_01aa);                   
\draw[->]               (Source_01ab) -- (Operation_01ab);                                      
\draw[->]               (Operation_01aa) -- (Operation_01ab);                                   
\draw[->]               (Source_01ac) -- (Operation_00ac);
\draw[->]               (Operation_01ab) -- (Operation_00ac);
\draw[->]               (Operation_00ac) -- (Target_01a);                               


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% BRANCH 01c. %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\node (Operation_01ca)  [AnOperation, below of=Origin, xshift=9cm]{};
\node (Source_01ca)     [Table,left of=Operation_01ca, xshift=-3cm] {}; 
\node (Target_01ca)     [TableTarget, below of=Operation_01ca]   {}; 
\node (Operation_01cb)  [AnOperation,below of=Target_01ca]    {};   
\node (Target_01cb)     [TableTarget, below of=Operation_01cb]  {}; 
\node(Operation_01cc)   [AnOperation, below of=Target_01cb] {01cc}; 

\draw[->]               (Source_01ca) --  (Operation_01ca);                                     
\draw[->]               (Origin) -| (Operation_01ca);       
\draw[->]               (Operation_01ca) -- (Target_01ca);      
\draw[->]               (Target_01ca) -- (Operation_01cb);      
\draw[->]               (Operation_01cb) -- (Target_01cb);      
\draw[->]               (Target_01cb) -- (Operation_01cc);                              

%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% RECOMBINE BRANCHES %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%  

\node (Target_02)   [TableTarget, below of=Operation_01cc, xshift=-9cm] {};

\draw[->]               (Operation_01cc) |- (Target_02);        
\draw[->]               (Target_01a) |- (Target_02);                            

%%%%%%%%%%%%%%%%%%%%%%%%%
%%% FURTHER OPERATION %%%
%%%%%%%%%%%%%%%%%%%%%%%%%

\node(Operation_03a)    [AnOperation, below of=Target_02] {};                                       
\node(Source_03a)       [Table, left of=Operation_03a, xshift=-3cm] {};                             
\node(Operation_03b)    [AnOperation, below of=Operation_03a] {};       
\node(Target_03b)       [TableTarget, below of=Operation_03b] {};
\node(future)           [TableTarget, below of=Target_03b] {};

\draw[->]               (Operation_03b) -- (Target_03b);  
\draw[->]               (Operation_03a) -- (Operation_03b); 
\draw[->]               (Source_03a) -- (Operation_03a);    
\draw[->]               (Target_02) -- (Operation_03a); 
\draw[->]               (Target_03b) -- (future);   

%%%%%%%%%%%%%%%%%%%%%
%% THE FINAL TABLE %%
%%%%%%%%%%%%%%%%%%%%%

\node(finalTarget)  [finalTarget, below of=future]  {};

\draw[->]           (future) -- (finalTarget);  
\draw[->]           (Origin)  -- (Target_02);                       

\end{tikzpicture}

\end{document}
  • 1
    Welcome to TeX.SX! Nice MWE! – egreg Jul 26 '17 at 9:39
2

You could extract the coordinates, but it is probably easier to use the fit library to create a node around the relevant operation and target nodes.

I'd also recommend the positioning library. below of= etc. is deprecated.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,fit,positioning}
\tikzset{%
  >={Latex[width=2mm,length=2mm]},
  base/.style = {rectangle, rounded corners, draw=black, minimum width=4cm, minimum height=1cm, text centered, font=\sffamily},
  Table/.style = {base, bottom color=yellow!70, top color=white},
  TableTarget/.style = {base, bottom color=green!75!black!70, top color=white},
  AnOperation/.style = {base, bottom color=gray!70, top color=white},
  finalTarget/.style = {base, bottom color=blue!70, top color=white, draw=blue},
}
\begin{document}
\begin{tikzpicture}[->, node distance=1.5cm, every node/.style={fill=white, font=\sffamily}, align=center, scale=0.8]

  \node (Origin)          [Table]{00};

  \node (Operation_00b)   [AnOperation, above of=Origin] {};
  \node(Source_00b)       [Table, left of=Operation_00b, xshift=-3 cm] {};
  \node (Operation_00a)   [AnOperation, above of=Operation_00b] {};
  \node(Source_00a)       [Table, left of=Operation_00a, xshift=-3 cm] {};
  \node (Source_Table)    [Table, above of=Operation_00a] {};

  \draw               (Source_Table)              -- (Operation_00a);
  \draw               (Source_00a)    -- (Operation_00a);
  \draw               (Operation_00a)         -- (Operation_00b);
  \draw               (Source_00b)        -- (Operation_00b);
  \draw               (Operation_00b)         -- (Origin);

  \node (Operation_01aa)  [AnOperation, below of=Origin, xshift=-9cm] {};
  \node (Source_01aa)     [Table, left of=Operation_01aa, xshift=-3cm] {};
  \node (Operation_01ab)  [AnOperation, below of=Operation_01aa] {};
  \node (Source_01ab)     [Table, left of=Operation_01ab, xshift = -3cm] {};
  \node (Operation_00ac)  [AnOperation, below of=Operation_01ab] {};
  \node (Source_01ac)     [Table, left of=Operation_00ac, xshift = -3cm]  {};
  \node (Target_01a)      [TableTarget, below of=Operation_00ac]      {01ac};

  \draw               (Source_01aa) -- (Operation_01aa);
  \draw               (Origin) -| (Operation_01aa);
  \draw               (Source_01ab) -- (Operation_01ab);
  \draw               (Operation_01aa) -- (Operation_01ab);
  \draw               (Source_01ac) -- (Operation_00ac);
  \draw               (Operation_01ab) -- (Operation_00ac);
  \draw               (Operation_00ac) -- (Target_01a);

  \node (Operation_01ca)  [AnOperation, below of=Origin, xshift=9cm]{};
  \node (Source_01ca)     [Table,left of=Operation_01ca, xshift=-3cm] {};
  \node (Target_01ca)     [TableTarget, below of=Operation_01ca]   {};
  \node (Operation_01cb)  [AnOperation,below of=Target_01ca]    {};
  \node (Target_01cb)     [TableTarget, below of=Operation_01cb]  {};
  \node(Operation_01cc)   [AnOperation, below of=Target_01cb] {01cc};

  \draw               (Source_01ca) --  (Operation_01ca);
  \draw               (Origin) -| (Operation_01ca);
  \draw               (Operation_01ca) -- (Target_01ca);
  \draw               (Target_01ca) -- (Operation_01cb);
  \draw               (Operation_01cb) -- (Target_01cb);
  \draw               (Target_01cb) -- (Operation_01cc);

  \node (f) [inner sep=0pt, draw=none, fill=none, fit=(Operation_01cc) (Target_01a)] {};
  \node (Target_02)   [TableTarget, below=of Origin |- f.south] {};

  \draw               (Operation_01cc) |- (Target_02);
  \draw               (Target_01a) |- (Target_02);

  \node(Operation_03a)    [AnOperation, below of=Target_02] {};
  \node(Source_03a)       [Table, left of=Operation_03a, xshift=-3cm] {};
  \node(Operation_03b)    [AnOperation, below of=Operation_03a] {};
  \node(Target_03b)       [TableTarget, below of=Operation_03b] {};
  \node(future)           [TableTarget, below of=Target_03b] {};

  \draw               (Operation_03b) -- (Target_03b);
  \draw               (Operation_03a) -- (Operation_03b);
  \draw               (Source_03a) -- (Operation_03a);
  \draw               (Target_02) -- (Operation_03a);
  \draw               (Target_03b) -- (future);

  \node(finalTarget)  [finalTarget, below of=future]  {};

  \draw           (future) -- (finalTarget);
  \draw           (Origin)  -- (Target_02);
\end{tikzpicture}
\end{document}

a fitting solution, possibly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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