2

I am trying to draw a flowchart. But the nodes are getting overlapped. This is the code:

\documentclass[12pt]{article}
\usepackage{cite}
\usepackage{graphicx}
\usepackage[a4paper, margin=1 in]{geometry}
\hfuzz=20pt
\vfuzz=20pt
\hbadness=2000
\vbadness=\maxdimen
\setlength{\arrayrulewidth}{0.5mm}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=white!30 ]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, text width=6cm, draw=black, fill=white!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=6cm, draw=black, fill=white!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, text width=6cm, draw=black, fill=white!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\nocite{*}
\begin{tikzpicture}[node distance=2cm]
\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Enter A and B and B`(A contains the bigger string)};
\draw [arrow] (start) -- (in1);
\node (pro1) [process, below of=in1] {big sentence: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa};
\draw [arrow] (in1) -- (pro1);
\node (dec1) [decision, below of=pro1] {any condition statement .................};
\draw [arrow] (pro1) -- (dec1);
\node (dec2) [decision, below of=dec1] {again a condition............................................................................};
\draw [arrow] (dec1) -- (dec2);
\node (dec3) [decision, below of=dec1] {Another one.................................................................................};
\draw [arrow] (dec1) -- (dec3);
\end{tikzpicture}
\end{document}

The nodes are not getting placed serially, they are getting overlapped

2
  • Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. And make sure, you get rid of those <br> that your code is marked as a code sample.
    – LaRiFaRi
    Jun 16 '15 at 6:36
  • Please read tex.stackexchange.com/q/9386 and tex.stackexchange.com/q/52372
    – LaRiFaRi
    Jun 16 '15 at 6:54
2

You should use the library positioning and the syntax below = of ....

You had some error with the references for the node placement.

The figure does not fit on one page, but here you are:

% arara: pdflatex

\documentclass[12pt]{article}
\usepackage[a4paper, margin=1 in]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, positioning}
\tikzset{%
    ,startstop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=white!30}
    ,io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, text width=6cm, draw=black, fill=white!30}
    ,process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=6cm, draw=black, fill=white!30}
    ,decision/.style={diamond, minimum width=3cm, minimum height=1cm, text centered, text width=6cm, draw=black, fill=white!30}
    ,arrow/.style={thick,->,>=stealth}
    }

\begin{document}
    \begin{tikzpicture}[node distance=.7cm]
    \node (start) [startstop] {Start};
    \node (in1) [io, below = of start] {Enter A and B and B`(A contains the bigger string)};
    \draw [arrow] (start) -- (in1);
    \node (pro1) [process, below = of in1] {big sentence: aaaaaaaaaaaaaaaaaaaaaaaaa\-aaaaaaaaaaaaaaaaaaaaaaaaaaa\-aaaaaaaaaaaaaaaaaaaaaaaa\-aaaaaaaaaaaaaaaaaaaaaaaa\-aaaaaaaaaaaaaaaaaaaaaaaaaa};
    \draw [arrow] (in1) -- (pro1);
    \node (dec1) [decision, below = of pro1] {any condition statement .................};
    \draw [arrow] (pro1) -- (dec1);
    \node (dec2) [decision, below = of dec1] {again a condition...............................\-.............................................};
    \draw [arrow] (dec1) -- (dec2);
    \node (dec3) [decision, below = of dec2] {Another one......................\-.............................\-..............................};
    \draw [arrow] (dec2) -- (dec3);
    \end{tikzpicture}
\end{document}
0
0

Based on @LaRiFaRi answer, however with small differences (to show another possible code):

  1. I move tikzset in tikzpicture
  2. common features of node I collect in every node/.style
  3. instead of fill color white!30 I use white (by the way, what color is white!30?)
  4. I reduce node distance to 1cm
  5. I add option aspect to diamond shape for reducing it height
  6. and brock "long words" (aaa ..., ....) in shorter words, that TeX will be able to form text in more lines.

    Code:

\documentclass[12pt]{article}
    \usepackage[a4paper, margin=1 in]{geometry}
    \usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes.geometric}

\begin{document}
    \begin{tikzpicture}[
node distance=1cm,
every node/.style = {draw, fill=white, align=center, minimum height=1cm},
%
 startstop/.style = {rectangle, rounded corners, minimum width=3cm},
        io/.style = {trapezium, trapezium left angle=70, trapezium right angle=110,
                     text width=6cm},
   process/.style = {rectangle, text width=6cm},
  decision/.style = {diamond, aspect=1.2, text width=6cm},
     arrow/.style = {thick,-stealth}
                        ]
\node (start) [startstop] {Start};
\node (in1) [io,below=of start] {Enter A and B and B`(A contains the bigger string)};
\draw [arrow] (start) -- (in1);
\node (pro1) [process,below=of in1] {big sentence: aaaaaa aaaaa aaaaaa aaaaa aaaaaaa aaaa aaaaaa aaaaaaaaa aaaaaaaa aaaaaaa aaaaa aaaaaaa aaaaaaaaa aaaaaaa aaaaaaaa aaaaaaa a aaa aaaaa aaaaaa aaaaa};
\draw [arrow] (in1) -- (pro1);
\node (dec1) [decision,below=of pro1] {any condition statement .................};
\draw [arrow] (pro1) -- (dec1);
\node (dec2) [decision,below=of dec1] {again a condition ...... ........ ......... ......... .. ..... ..... .. ... ..... ... .... .... .... .... ...};
\draw [arrow] (dec1) -- (dec2);
\node (dec3) [decision,below=of dec1] {Another one... ..... ..... .... ... .... ..... .... ... .... .... ...... ... .... ..... .. ...... ...... .....};
\draw [arrow] (dec1) -- (dec3);
\end{tikzpicture}
\end{document}

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.