[Tex/LaTex] How to draw flowchart-Diagram with text

diagramstikz-pgf

\documentclass{article}

%\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows} % For flowchart and Diagram

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}  % For flowchart and Diagram
\PreviewEnvironment{tikzpicture}  % For flowchart and Diagram
\setlength\PreviewBorder{60pt}% to control size of the diagram, to reduce increase +ve value
%%%>

\begin{document}
\pagestyle{empty}

Text here

% Define block styles
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=2.5cm,minimum height=2em]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110,minimum height=2em,text centered, draw=black, fill=blue!30]
\tikzstyle{decision} = [diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em]
  \tikzstyle{line} = [draw, -latex']  
\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [io] (init) {Initialize};
    \node [cloud, above of=init] (Start) {Start};
    \node [cloud, right of=init] (system) {system};
    \node [block, below of=init] (identify) {Process};
    \node [block, below of=identify] (evaluate) {Evaluate};
    \node [block, left of=evaluate, node distance=3cm] (update) {update model};
    \node [decision, below of=evaluate] (decide) {Decision};
    \node [cloud, below of=decide, node distance=3cm] (Stop) {Stop};
    % Draw edges
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) -| node [near start] {yes} (update);
    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {no}(Stop);
    \path [line,dashed] (Start) -- (init);
    \path [line,dashed] (system) -- (init);
    \path [line,dashed] (system) |- (evaluate);
\end{tikzpicture}


\end{document}

This gives

enter image description here

I want to draw this diagram with description. But this produces dragram only ignoring other text in the same document. How can I do the wok I wat?

Best Answer

If I understand properly, you may want remove these lines

\usepackage[active,tightpage]{preview}  % For flowchart and Diagram
\PreviewEnvironment{tikzpicture}  % For flowchart and Diagram
\setlength\PreviewBorder{60pt}% to control size of the diagram, to reduce increase +ve value

These lines are meant to produce a tight picture, not to be used in a regular document. Without these lines your code:

\documentclass{article}
\usepackage{lipsum}
%\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows} % For flowchart and Diagram

%%%<
\usepackage{verbatim}
%\usepackage[active,tightpage]{preview}  % For flowchart and Diagram
%\PreviewEnvironment{tikzpicture}  % For flowchart and Diagram
%\setlength\PreviewBorder{60pt}% to control size of the diagram, to reduce increase +ve value
%%%%>

\begin{document}
\pagestyle{empty}

Text here

% Define block styles
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=2.5cm,minimum height=2em]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110,minimum height=2em,text centered, draw=black, fill=blue!30]
\tikzstyle{decision} = [diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em]
  \tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [io] (init) {Initialize};
    \node [cloud, above of=init] (Start) {Start};
    \node [cloud, right of=init] (system) {system};
    \node [block, below of=init] (identify) {Process};
    \node [block, below of=identify] (evaluate) {Evaluate};
    \node [block, left of=evaluate, node distance=3cm] (update) {update model};
    \node [decision, below of=evaluate] (decide) {Decision};
    \node [cloud, below of=decide, node distance=3cm] (Stop) {Stop};
    % Draw edges
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) -| node [near start] {yes} (update);
    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {no}(Stop);
    \path [line,dashed] (Start) -- (init);
    \path [line,dashed] (system) -- (init);
    \path [line,dashed] (system) |- (evaluate);
\end{tikzpicture}
\lipsum

\end{document}

enter image description here

Notes:

  1. Use \tikzset instead of \tikzstyle which is deprecated.
  2. Use positioning library and use below=of, right = of syntax for better placement (instead of below of=).