2

How can I make the connection as shown in the figure attached? I have a line commented on my code which I tried but is not working.

    \documentclass{article}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.arrows}
\usepackage{array}

\begin{document}
\begin{tikzpicture} [
    auto,
    decision/.style = { diamond, draw=black, thick, fill=gray!30, text width=5em, text centered, inner sep=1pt },
    block/.style    = { rectangle, draw=black, thick, fill=white, text width=10em, text centered, minimum height=2em },
    line/.style     = { draw, thick, ->, shorten >=1pt },
  ]
  % Define nodes in a matrix
  \matrix [column sep=5mm, row sep=6mm] {
                    & \node [block] (H) {Calculate H};                              & \\
                    & \node [block] (eq3) {Solve Eq.3};                             & \\
                    & \node [decision] (y) {$y\left(\frac{L}{2}\right)=h$};         & \\
                    & \node [block] (Dy) {Update $y(x)$};                           & \\
                    & \node [block] (Hnew) {Calculate H};                           & \\
                    & \node [decision] (HH) {H changed?};                           & \\
                    & \node [text centered] (out) {Results};                        & \\
  };
  % connect all nodes defined above
  \begin{scope} [every path/.style=line]
    \path (H)       --      (eq3);
    \path (eq3)     --      (y);
    \path (HH)      --++    (-3,0) node [near start] {yes} |- (eq3);
    \path (y)       --      node [near start] {no} (Dy);
%    \path (y)      --      (3,0) node [near start] {yes} -| (Hnew); THIS WAS MY TRY!!! NOT WORKING
    \path (Dy)      --      (Hnew);
    \path (Hnew)    --      (HH);
    \path (HH)      --      node [near start] {no} (out);
  \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

2

if you change line

%    \path (y) -- (3,0) node [near start] {yes} -| (Hnew); THIS NOT WORKING

in your mwe to

 \path (y.east)  node [above right] {yes} -- + (2,0) |- (Hnew);

you will obtain:

enter image description here

however, since flowchart is relative simple, its code can be simplified by use of chains instead of matrix:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains, positioning, shapes}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%

\begin{document}
\begin{tikzpicture} [
  node distance = 5mm and 1mm,
    start chain = A going below,
decision/.style = { diamond, aspect=1.5, draw=black, thick, fill=gray!30,
                    text width=5em, align=center, inner sep=1pt,
                    on chain=A, join=by line},
   block/.style = { rectangle, draw=black, thick, fill=white,
                    text width=10em, align=center,  minimum height=2em,
                    on chain=A, join=by line},
    line/.style = { draw, thick, ->, shorten >=1pt },
                    ]
  % Define nodes in a matrix
\node [block]       {Calculate H};                      % A-1
\node [block]       {Solve Eq.3};                       % A-2
\node [decision]    {$y\left(\frac{L}{2}\right)=h$};    % A-3
\node [block]       {Update $y(x)$};                    % A-4
\node [block]       {Calculate H};                      % A-5
\node [decision]    {H changed?};                       % A-6
% non join nodes' connections
\draw[line] (A-6.west) node [above  left] {yes} -- + (-2,0) |- (A-2);
\draw[line] (A-3.east) node [above right] {yes} -- + ( 2,0) |- (A-5);
% edge labels
\node[below right] at (A-3.south) {no};
\draw[line] (A-6.south)  -- ++  (0,-0.6) node [below] {Results};
\end{tikzpicture}
\end{document}
  • Thanks a lot Zarko. It's my very first time making this kind of diagrams in Latex and I just found an example which I changed to adapt to my needs. I was almost sure there were way simpler methods to do it. Thanks again for the help and the hints. – Carlos Cordeiro Dec 1 '17 at 9:00
  • @CarlosCordeiro, you are welcome! happy tex-ing! – Zarko Dec 1 '17 at 9:06

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.