3

Good day! I'm not satisfied with the flowchart I made for my thesis. Could someone help me improve it? Also, I want to make the text/caption of the path/line into vertical one. Please help. Thank you

\documentclass[12pt,letterpaper]{article}
\usepackage[margin=1in]{geometry}

\usepackage[latin1]{inputenc}
\usepackage{tikz,amsmath,amssymb,amsthm,epsfig}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!23, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block1} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=5em]
\tikzstyle{block2} = [rectangle, draw, fill=blue!10, 
    text width=8em, text centered, minimum height=10em]
\tikzstyle{block3} = [rectangle, draw, fill=purple!30, 
    text width=13em, text centered, minimum height=5em]
\tikzstyle{line} = [draw, thick, -latex']
\tikzstyle{cloud1} = [draw, ellipse,fill=red!18, node distance=4cm,
    minimum height=5em]
\tikzstyle{cloud2} = [draw, ellipse,fill=green!18, node distance=5cm,
    minimum height=5em, text width=7em]
\tikzstyle{block4}= [rectangle, draw, fill=orange!18,   
   text width=12em, text centered, minimum height=8em]

\begin{tikzpicture}[node distance = 3cm, auto]
    % Place nodes
    \node [cloud1] (input) {INPUT};
    \node [cloud2, below of=input, node distance=2.5cm] (mn) {$L(m,1),W(3,n)$ where $m,n \in \mathbb{N}$};
    \node [block1, left of=mn, node distance=6cm] (step1) {STEP 1:};
    \node [block2, left of=step1, node distance=5cm] (vertex) {$V(W(3,n)) = \{v\} \cup \{v_{(i,j)} | i \in \{1,2,3,\ldots,n\} , j \in \{1,2,3\} \}$};
    \node [block2, below of=vertex, node distance=5cm] (edge) {$E(W(3,n))= \{ vv_{(i,j)} | i \in \{1,2,\ldots,n\} , j \in \{1,2,3\}\} \cup \{v_{(i,j)}v_{(i,j+1)} | i \in \{1,2,\ldots,n\} , j \in \{1,2,\}\} \cup \{ v_{(i,1)}v_{(i,3)} | i \in \{1,2,\ldots,n\}\}$};
    \node [block1, right of=edge, node distance=5cm] (step2) {STEP 2:};
    \node [block3, below of=step2, node distance=3cm] (v) {Let $\ell : V(W(3,n)) \longrightarrow \{0,1,2,\ldots\}$ where $\ell(v_0)=0$};
    \node [decision, below of=v, left of=v, node distance=4cm] (geq) {$m\geq n$};
    \node [block3, right of=geq, node distance=7cm] (1) {$\ell(V_{(i,j)})=jm+(i-1), i \in \{1,2,\ldots n\}, j \in \{1,2,3\}$};
    \node [decision, below of=geq] (lessthan) {$m<n$};
    \node [block3, right of=lessthan, node distance=7cm] (2) {$\ell(v_{i,j})=jm+(j-1)(n-m)+(i-1), i \in \{1,2,3,\ldots,n\}$ and $j \in \{1,2,3\}$};
    \node [cloud2, below of=2, right of=2, node distance=4.5cm] (labeled) {Each vertex has label.};
    \node [cloud1, left of=labeled, node distance=5cm] (output) {OUTPUT};
    \node [block4, left of=output, node distance=5cm] (optimal) {Optimal $L(m,1)$-labeling for triangular windmill graph $(W(3,n))$.};


    % Draw edges
    \path [line] (input) --  (mn);
    \path [line] (mn) -- (step1);
    \path [line] (edge) -- (step2);
    \path [line] (step1) -- (vertex);
    \path [line] (vertex) -- (edge);
    \path [line] (step2) -- (v);
    \path [line] (v) -| node {and} (geq);
    \path [line] (geq) -- node {TRUE} (1);
    \path [line] (geq) -- node {FALSE}(lessthan);
    \path [line] (lessthan) -- node {TRUE}(2);
    \path [line] (1) -| node [near start] {TRUE} (labeled);
    \path [line] (2) -| node [near start] {TRUE} (labeled);
    \path [line] (labeled) -- node {TRUE} (output);
    \path [line] (output) -- (optimal);
    \draw [->,thick] (labeled.north) -- ++(0,0)  -- ++(10mm,5mm) |- node [ near start, yshift=1.5em]{FALSE} (step2);

\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588
Angie Vii
  • 51
  • 1
  • 1
  • 4
  • 1
    Hi, welcome. Except for obviously bad placement of the "and" label, do you have any thoughts about what you want improve, specifically? By vertical, do you mean that you want to rotate e.g. the "FALSE" label by 90 degrees? – Torbjørn T. Jan 31 '18 at 11:46
  • Yes, I would like to rotate the 'FALSE" so that it will look like flat in above or under the line. Thanks for your help! :) – Angie Vii Jan 31 '18 at 12:41
  • Also, I want to add \centering \textbf{ \Large FLOWCHART} above the flowchart, but I have difficulties fitting this on one page. Please help me to resize the chart. Thank you! – Angie Vii Jan 31 '18 at 13:33
  • Anything else you had in mind? – Torbjørn T. Jan 31 '18 at 13:35
  • I'm still thinking about other things to change, but now that would be all. Thank you so much! – Angie Vii Jan 31 '18 at 13:37

2 Answers2

4

There will be many ways of doing this, here is one possibility.

I've "modernized" the code a bit, using \tikzset instead of \tikzstyle (Should \tikzset or \tikzstyle be used to define TikZ styles?) and used the positioning library (Difference between "right of=" and "right=of" in PGF/TikZ). I also removed all node distances from the styles themselves.

The colours are entirely a personal preference, I grabbed some from Colorbrewer, change back to the original ones if you prefer those.

I moved the input node below the mn node, which saves a lot of vertical space. It is possible to have it above though, and still fit the page.

The frame you see in the image indicates the textblock, and is generated by the showframe option I added to the geometry package, you want to remove that option in your document.

output of code

\documentclass[12pt,letterpaper]{article}
% added showframe option to indicate size of text block
\usepackage[margin=1in,showframe]{geometry}
\usepackage[latin1]{inputenc}
\usepackage{tikz,amsmath,amssymb,amsthm}
% the arrows library is deprecated in favor of arrows.meta
% the positioning library is recommended for relative positioning
\usetikzlibrary{shapes,arrows.meta,positioning}

% colors are a matter of personal preference, these are from
% http://colorbrewer2.org/#type=qualitative&scheme=Set2&n=7
\definecolor{clr1}{RGB}{102,194,165}
\definecolor{clr2}{RGB}{252,141,98}
\definecolor{clr3}{RGB}{141,160,203}
\definecolor{clr4}{RGB}{231,138,195}
\definecolor{clr5}{RGB}{166,216,84}
\definecolor{clr6}{RGB}{255,217,47}
\definecolor{clr7}{RGB}{229,196,148}

% Define block styles
% \tikzstyle is considered deprecated in favor of the more 
% general \tikzset I believe
% I removed all the node distance settings from the various styles
\tikzset{
  decision/.style={diamond, draw, fill=clr1, 
    text width=4.5em, text badly centered, inner sep=0pt},
  block1/.style={rectangle, draw, fill=clr2, 
    text width=5em, text centered, rounded corners, minimum height=5em},
  block2/.style={rectangle, draw, fill=clr3, 
    text width=10em, text centered, minimum height=6em},
  block3/.style={rectangle, draw, fill=clr4, 
    text width=13em, text centered, minimum height=5em},
  line/.style={draw, thick, -Latex},
  cloud1/.style={draw, ellipse,fill=clr5, 
    minimum height=5em},
  cloud2/.style={draw, ellipse,fill=clr6, 
    minimum height=5em, text width=7em},
  block4/.style={rectangle, draw, fill=clr7,   
   text width=12em, text centered, minimum height=8em}
}

\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[node distance = 7mm, auto]
    % Place nodes
    \node [cloud1]                         (input)    {INPUT};
    % in order to save space, this is placed above the input
    % but there is still room to have it the other way around, if that is preferred
    \node [cloud2, above=of input]         (mn)       {$L(m,1),W(3,n)$ where $m,n \in \mathbb{N}$};
    \node [block1, left=1cm of mn]         (step1)    {STEP 1:};
    \node [block2, left=2.3cm of step1]    (vertex)   {$V(W(3,n)) = \{v\} \cup \{v_{(i,j)} |
                                                       i \in \{1,2,3,\ldots,n\} , j \in \{1,2,3\} \}$};
    \node [block2, below=of vertex]        (edge)     {$E(W(3,n))= \{ vv_{(i,j)} | i \in \{1,2,\ldots,n\} ,
                                                       j \in \{1,2,3\}\} \cup \{v_{(i,j)}v_{(i,j+1)} | 
                                                       i \in \{1,2,\ldots,n\} , 
                                                       j \in \{1,2,\}\} \cup \{ v_{(i,1)}v_{(i,3)} |
                                                       i \in \{1,2,\ldots,n\}\}$};
    % note this is placed at (edge-|step1) for horizontal alignment,
    % and to avoid repeating node distances
    \node [block1, at={(edge-|step1)}]     (step2)    {STEP 2:};
    \node [block3, below=1.3cm of step2]   (v)        {Let $\ell : V(W(3,n)) \longrightarrow \{0,1,2,\ldots\}$ where $\ell(v_0)=0$};
    \node [decision,
           below left=1cm and 2.5cm of v]  (geq)      {$m\geq n$};
    \node [block3, at={(geq-| v)}]         (1)        {$\ell(V_{(i,j)})=jm+(i-1), i \in \{1,2,\ldots n\}, j \in \{1,2,3\}$};
    \node [decision, below=of geq]         (lessthan) {$m<n$};
    \node [block3, at={(lessthan -| 1)}]   (2)        {$\ell(v_{i,j})=jm+(j-1)(n-m)+(i-1), i \in \{1,2,3,\ldots,n\}$ and $j \in \{1,2,3\}$};
    \node [cloud2,
           right=-5mm of 2, yshift=-3.5cm] (labeled)  {Each vertex has label.};
    \node [cloud1, left=2cm of labeled]    (output)   {OUTPUT};
    \node [block4, left=of output]         (optimal)  {Optimal $L(m,1)$-labeling for triangular windmill graph $(W(3,n))$.};


    % Draw edges
    \path [line] (input) --  (mn);
    \path [line] (mn) -- (step1);
    \path [line] (edge) -- (step2);
    \path [line] (step1) -- (vertex);
    \path [line] (vertex) -- (edge);
    \path [line] (step2) -- (step2 |- v.north);
    % added [pos=0.25] for the node
    % in a -| path, midway/pos=0.5 is at the corner, so 0.25 is halfway to the corner
    \path [line] (v) -| node [pos=0.25] {and} (geq);
    \path [line] (geq) -- node {TRUE} (1);
    \path [line] (geq) -- node  {FALSE} (lessthan);
    \path [line] (lessthan) -- node {TRUE}(2);
    \path [line] (1) -| node [near start] {TRUE} (labeled);
    \path [line] (2) -| node [near start] {TRUE} (labeled);
    \path [line] (labeled) -- node {TRUE} (output);
    \path [line] (output) -- (optimal);
    % added sloped, above to the node options to rotate it
    \path [line] (labeled.north) -- ++(10mm,5mm) |- node [pos=0.3,sloped,above] {FALSE} (step2);

    % place node relative to the current bounding box
    \node [above=2ex, font=\bfseries\Large] at (current bounding box.north) {FLOWCHART};
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688
0

Having put a few flowcharts in my thesis, I'd say you're doing well, and now you're at the fiddling stage: adjusting things by hand to optimise.

One thing I would change is the Each vertex has label -- FALSE line, as it currently leaves at the entry point (north). East would look better though it would make your flowchart a little wider.

You can move the last box left a little to uncrowd the TRUE just before OUTPUT. If you also move the two pink boxes above OUTPUT to the left, it will look more balanced, and/or you can move Each vertex has label left to regain some of the width lost to taking the FALSE edge out from the east.

Chris H
  • 8,705
  • Thank you for your suggestion. I will try it. :) But I'm afraid that it wouldn't fit the paper if I'm going to have its hard copy. – Angie Vii Jan 31 '18 at 12:54
  • Also, I want to add \centering \textbf{ \Large FLOWCHART} above the flowchart, but I have difficulties fitting this on one page. Please help me to resize the chart. Thank you! – Angie Vii Jan 31 '18 at 13:35
  • If you reduce the minimum height of block2 you'll save a lot of wasted vertical space in the box starting $V(W(3,n)). Yo umight want to do the same in block3 and block4 as well. Then you can play with some of the node distances, like the one in (labeled). But a heading "FLOWCHART" isn't what you'd normally do in a thesis (apart from the fact it's obviously a flowchart). I'd expect the flowchart to be a float, and a numbered figure with a caption ("Figure 1.1: Flowchart showing the process for..."). – Chris H Jan 31 '18 at 14:00
  • ..and that's before you just reduce the font for everything. I had \begin{tikzpicture}[node distance = 0.5cm, auto, font=\fontsize{6.8pt}{1em}\sffamily\mathversion{sans}, inner sep =0.8mm] as I also prefer sans fonts in figures, especially when rotated. I also made some nodes wider to reduce the number of lines in them – Chris H Jan 31 '18 at 14:03
  • 1
    I"ll just place this in the Appendices so I want to put the FLOWCHART label on top since I will not write some captions or explanation of it. – Angie Vii Jan 31 '18 at 14:19