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

dyluns
  • 5
Harry
  • 961
  • 2
  • 11
  • 27
  • @PaulGessler the one I wrote terrible, code doesn't compile either – Harry Mar 29 '14 at 00:05
  • @cmhughes I just cut and paste and then run the given example above. But it doesn't compile – Harry Mar 29 '14 at 01: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 Mar 29 '14 at 01:31
  • @cmhughes Yeah.I did that, but still I can't compile Jake's code. – Harry Mar 29 '14 at 01:47
  • @cmhughes When I run the command both in WinEdt8 and tex studio, it stops at \path [>=latex,->] (m-1-1) edge (m-2-1); and every other \path commands – Harry Mar 29 '14 at 02:00
  • 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 Mar 29 '14 at 03:30
  • @cmhughes Does it compile for you? I get an error at the same point. I'm wondering if the problem is that my installation is updated so that I have tikz 3. I notice that code is from a bit ago and still, for example, uses arrows etc. – cfr Mar 29 '14 at 03:34
  • It works if you label the nodes by hand or if you use a regular, plain matrix without specifying e.g. \node. – cfr Mar 29 '14 at 03:48
  • May be you can look a this example http://texample.net/tikz/examples/flexible-flow-chart/ – Ignasi Mar 29 '14 at 06:44
  • @cmhughes I have tried but it gives error. Could you please help me to finish this. Many thanks – Harry Mar 31 '14 at 02:26
  • @cfr I have tried the code. Please refer to the modefied version of the problem. – Harry Mar 31 '14 at 02:27
  • So what works 'fine', what 'gives error' and which code did you try? That code compiles OK here now. It just is too large so you need to adjust the sizing to fit it onto the sheet or use a larger piece of paper. – cfr Mar 31 '14 at 03:03
  • @cfr Can't we code that to use two columns of the paper? – Harry Mar 31 '14 at 22:59
  • @Harry Why don't you just change the direction so that before the end of the page, you switch the flowchart to the right or whatever? As in the image you posted? – cfr Mar 31 '14 at 23:51
  • By the way, it's "optimality criterion", not "optimilalty cretierin". – LSpice Aug 29 '21 at 15:10

1 Answers1

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}

dyluns
  • 5
cfr
  • 198,882