LaTeX forum ⇒ Graphics, Figures & TablesTikz | Simple flow chart

Information and discussion about graphics, figures & tables in LaTeX documents.
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm
Contact:

Tikz | Simple flow chart

Postby bkarpuz » Wed Dec 19, 2012 9:52 pm

Dear LC members,

I have a flow chart which consists of a parallelogram, a rectangle, a diamond and a trapezoid as attached. I tried myself but could not get any successful results and I couldn't combine with No line Query and Operations box. I would really appreciate your help on giving me a flow chart sample.

Thank you very much.
bkarpuz
Attachments
FlowChart.JPG
FlowChart.JPG (11.26 KiB) Viewed 4819 times

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7801
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Wed Dec 19, 2012 10:10 pm

Hello,

bkarpuz wrote:I tried myself but could not get any successful results


what did you try? Perhaps we can continue that instead that reader start from scratch.

bkarpuz wrote:I couldn't combine with No line Query and Operations box.


It should be no problem. Once we see your code I guess we are able to show how to do the connection.

Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm
Contact:

Postby bkarpuz » Wed Dec 19, 2012 10:39 pm

Stefan_K wrote:Hello,

bkarpuz wrote:I tried myself but could not get any successful results


what did you try? Perhaps we can continue that instead that reader start from scratch.

bkarpuz wrote:I couldn't combine with No line Query and Operations box.


It should be no problem. Once we see your code I guess we are able to show how to do the connection.

Stefan


Thank you Stefan_K.
Here is my code.
  1. \documentclass{article}
  2.  
  3. \usepackage{tikz}
  4.  
  5. \usetikzlibrary{shapes,arrows,shapes.multipart}
  6.  
  7. \begin{document}
  8.  
  9. \tikzset{
  10. startend/.style = {draw, circle},
  11. input/.style = {draw, trapezium, trapezium left angle=70, trapezium right angle=-70, minimum height=4em},
  12. print/.style = {draw, trapezium, trapezium left angle=-70, trapezium right angle=-70, minimum height=4em},
  13. operation/.style = {rectangle, draw, text width=17em, text centered, minimum height=4em},
  14. question/.style = {diamond, draw, text width=8em, text centered, inner sep=0pt},
  15. line/.style = {draw, -latex'}
  16. }
  17.  
  18. \begin{tikzpicture}[node distance = 3cm, auto]
  19. \node [startend] (start) {Start};
  20. \node [input, below of=start] (input) {$h,n_{0},x_{0},y_{0}$};
  21. \node [operation, below of=input] (operationa) {$n=0$};
  22. \node [operation, below of=operationa] (operationb) {$n=n+1$\\ $x_{n}=x_{n-1}+h$\\ $y_{n}=y_{n-1}+hf(x_{n-1},y_{n-1})$};
  23. \node [question, below of=operationb] (question) {$x_{n}\geq{}x_{0}+n_{0}h$};
  24. \node [print, below of=question] (print) {$x_{0},y_{0}$};
  25. \node [startend, below of=print] (end) {End};
  26.  
  27. \path [line] (start) -- (input);
  28. \path [line] (input) -- (operationa);
  29. \path [line] (operationa) -- (operationb);
  30. \path [line] (operationb) -- (question);
  31. \path [line] (question) -- node {No} (operationb);
  32. \path [line] (question) -- node {Yes} (print);
  33. \path [line] (print) -- (end);
  34. \end{tikzpicture}
  35.  
  36. \end{document}

This one also looks as the distance between the elements are not spaced good.

Thank you.
bkarpuz

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7801
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Wed Dec 19, 2012 11:10 pm

I guess the spacing is between the anchors / centers of the nodes, and they have a different height. You could specify an yshift value, or use relative positioning such as below =4cm of nodename.

The missing path can be done like

  1. \path [line] (question) -- ++(-4,0) |- (operationb);


which means going 4 to the left and connecting to operationb horizontally and then vertically.

flowchart.png
flowchart.png (5.14 KiB) Viewed 4812 times


Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm
Contact:

Postby bkarpuz » Thu Dec 20, 2012 9:37 am

Stefan_K wrote:The missing path can be done like
  1. \path [line] (question) -- ++(-4,0) |- (operationb);

which means going 4 to the left and connecting to operationb horizontally and then vertically.

Thank you Stefan_K, I have modified it as follows for my purpose
  1. \path [line] (question) -- node {No} ++(-4,0) |- (operationb);

On the other hand, why there letters are scattered in the equation $n=n+1$ and the others? How can I make them look like as in the mathematical text.
Also it is possible to edit the lines so that I adjust manually the distance between each object?

Thanks once more.
bkarpuz
Last edited by bkarpuz on Fri Dec 21, 2012 7:51 am, edited 1 time in total.

Link:
BBcode:
HTML:
Hide post links
Show post links

bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm
Contact:

Postby bkarpuz » Fri Dec 21, 2012 7:50 am

Stefan_K wrote:You could specify an yshift value, or use relative positioning such as below =4cm of nodename.

The following line does not compile.
  1. \node [input] (input) {$h,n_{0},t_{0},y_{0}$};
  2. \node [operation, below=2cm of input] (operationa) {$n=0$};

What is the problem with this line?

Thank you.
bkarpuz

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests