20

I have to write a flow chart given by figure below

enter image description here

I have used the packages,

\usepackage{tikz}

\usetikzlibrary{shapes,arrows}

But I couldn't get what I want. I hope some LaTeX experts here can help me with this.

Other option is using algorithm2e package, Is that possible to have both codes?

When I use the half commands it goes to other page? How to I write complete flow chart in one page ?

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}

\begin{document}

% Define block styles
\tikzset{
decision/.style={
    diamond,
    draw,
    text width=4em,
    text badly centered,
    inner sep=0pt
},
block/.style={
    rectangle,
    draw,
    text width=10em,
    text centered,
    rounded corners
},
cloud/.style={
    draw,
    ellipse,
    minimum height=2em
},
descr/.style={
    fill=white,
    inner sep=2.5pt
},
connector/.style={
    -latex,
    font=\scriptsize
},
rectangle connector/.style={
    connector,
    to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
    pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
    connector,
    to path=--(\tikztotarget) \tikztonodes
}
}

\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]{
    |[block]| {Start};               &  \\
    |[block]| {Assume that $a=c$ the optimilalty cretierin given by }               &                                            \\
    |[decision]| {Locally optimal}          &                                             \\
   |[block]| {Assume that $a=d$ the optimilalty cretierin given by}    &                                             \\
    |[decision]| {Locally optimal}         &                                             \\
         |[block]| {Assume that $a=e$ the optimilalty cretierin given by}    &                                             \\
            |[decision]| {Locally optimal}         &                                             \\
                 |[block]| {Assume that $a=f$ the optimilalty cretierin given by}    &                                             \\
                    |[decision]| {Locally optimal}         &                                             \\
                         |[block]| {Assume that $a=k$ the optimilalty cretierin given by}    &                                             \\
                            |[decision]| {Locally optimal}         &                                             \\
    |[block]| {Stop};                           &                                             \\
};
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\path [>=latex,->] (m-3-1) edge (m-4-1);
\path [>=latex,->] (m-4-1) edge (m-5-1);
\path [>=latex,->] (m-5-1) edge (m-6-1);
\path [>=latex,->] (m-6-1) edge (m-7-1);
\path [>=latex,->] (m-7-1) edge (m-8-1);
\path [>=latex,->] (m-8-1) edge (m-9-1);
\path [>=latex,->] (m-9-1) edge (m-10-1);
\path [>=latex,->] (m-10-1) edge (m-11-1);
\path [>=latex,->] (m-11-1) edge (m-12-1);

\end{tikzpicture}

\end{document}

enter image description here

16
  • @PaulGessler the one I wrote terrible, code doesn't compile either
    – Harry
    Commented Mar 29, 2014 at 0:05
  • possible starting point: Arrows at right angles on a tikzpicture matrix
    – cmhughes
    Commented Mar 29, 2014 at 0:42
  • @cmhughes I just cut and paste and then run the given example above. But it doesn't compile
    – Harry
    Commented Mar 29, 2014 at 1:27
  • @Harry did you run Jake's code? If it didn't compile for you, you might need to update your distribution: How do I update my TeX distribution?
    – cmhughes
    Commented Mar 29, 2014 at 1:31
  • 4
    Note that even code which doesn't compile or is 'terrible' will save people time in trying to help if only because you provide at least a minimal framework for the document.
    – cfr
    Commented Mar 29, 2014 at 3:30

1 Answer 1

16

For example:

Flowchart diversion to right

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}

\begin{document}

% Define block styles
\tikzset{
decision/.style={
    diamond,
    draw,
    text width=4em,
    text badly centered,
    inner sep=0pt
},
block/.style={
    rectangle,
    draw,
    text width=10em,
    text centered,
    rounded corners
},
cloud/.style={
    draw,
    ellipse,
    minimum height=2em
},
descr/.style={
    fill=white,
    inner sep=2.5pt
},
connector/.style={
    -latex,
    font=\scriptsize
},
rectangle connector/.style={
    connector,
    to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
    pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
    connector,
    to path=--(\tikztotarget) \tikztonodes
}
}

\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]{
    |[block]| {Start}              &  \\
    |[block]| {Assume that $a=c$ the optimilalty cretierin given by }               &                                            \\
    |[decision]| {Locally optimal}          &                                             \\
   |[block]| {Assume that $a=d$ the optimilalty cretierin given by}    &                                             \\
    |[decision]| {Locally optimal}         &           |[block]| {Stop}                                   \\
         |[block]| {Assume that $a=e$ the optimilalty cretierin given by}    &    |[decision]| {Locally optimal}                                          \\
            |[decision]| {Locally optimal}         &       |[block]| {Assume that $a=k$ the optimilalty cretierin given by}                                      \\
                 |[block]| {Assume that $a=f$ the optimilalty cretierin given by}    &   |[decision]| {Locally optimal}                                         \\
};
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\path [>=latex,->] (m-3-1) edge (m-4-1);
\path [>=latex,->] (m-4-1) edge (m-5-1);
\path [>=latex,->] (m-5-1) edge (m-6-1);
\path [>=latex,->] (m-6-1) edge (m-7-1);
\path [>=latex,->] (m-7-1) edge (m-8-1);
\path [>=latex,->] (m-8-1) edge (m-8-2);
\path [>=latex,->] (m-8-2) edge (m-7-2);
\path [>=latex,->] (m-7-2) edge (m-6-2);
\path [>=latex,->] (m-6-2) edge (m-5-2);

\end{tikzpicture}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .