Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to draw the following diagram using TikZ package in LaTeX

enter image description here

I wrote the following code so far:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
    \begin{tikzpicture}[auto, node distance=2cm,>=latex']
        \tikzstyle{block} = [draw, rectangle];
        \tikzstyle{rblock}=[draw, shape=rectangle,rounded corners=0.5em];
        \node [rblock] (start) {Start};
        \node [block, right of=start] (acquire) {Acquire Image};
        \node [block, right of=acquire] (rgb2gray) {RGB to Gray};
        \node [block, right of=rgb2gray] (otsu) {Localized OTSU Thresholding};
        \node [block, below of=otsu] (gchannel) {Subtract the Green Channel};
        \node [block, left of=gchannel] (closing) {Morphological Closing};
    \end{tikzpicture}
\end{document}

But the result I get is really bad and all the boxes are on top of each other. Please note, in my code "Subtract the Green Channel" node is below "Localized Otsu Thresholding" but that is also fine, flow diagram can flow either way but preferably the one shown in image.

Could someone please tell me what I'm missing? How can I fix the length of box and let text within them span multiple lines? If possible an someone provide me LaTeX code that could draw flow diagram as shown in image? Any help would be appreciated.

Thanks everyone who answered. I've got this far:

Progress so far

The code I used is below:

\begin{tikzpicture}[>=latex']
    ikzset{block/.style= {draw, rectangle, align=center,minimum width=2cm,minimum height=1cm},
    rblock/.style={draw, shape=rectangle,rounded corners=1em,align=left,minimum width=1.5cm,minimum height=0.75cm},
    input/.style={ % requires library shapes.geometric                                                                                                                                                                                         
      draw,
      trapezium,
      trapezium left angle=60,
      trapezium right angle=120,
      minimum width=2.0em,
      align=center,
      minimum height=1.5em
    },
  }


\node [rblock] (start) {Start};  
\node [block, right =1.75em of start] (acquire) {Acquire Image};

\node [block, right =1.75em of acquire] (rgb2gray) {RGB to Gray};
\node [block, below =1.75em of rgb2gray.south] (otsu) {Localized OTSU \\ Thresholding};
\node [block, left =1.75em  of otsu] (gchannel) {Subtract the Green \ Channel};
\node [block, below left =1.75em of gchannel] (closing) {Morphological \\ Closing};
\node [block, right =1.75em of closing] (NN) {Sign Detection \\ Using NN};
\node [input, right  =1.75em of NN] (limit) {Speed \\ Limit};
\node [coordinate, right =1em of otsu.east] (otsu_right) {};  %% Coordinate on right and middle                                                                                                                                              

  %% paths                                                                                                                                                                                                                                     
  \path[draw,->] (start) edge (acquire)
  (acquire) edge (rgb2gray)
  (rgb2gray.east) -| (otsu_right) -- (otsu.east)
  (otsu) edge  (gchannel)
%  (gchannel) edge (closing)                                                                                                                                                                                                                   
%  (closing) edge (NN)                                                                                                                                                                                                                         
%  (NN) edge (limit)                                                                                                                                                                                                                           
  ;
\end{tikzpicture}

I'm using two column paper style therefore you fit things in, I've putting less number of boxes each line. I want that RGB to Gray node should be right aligned with Localized OTSU node and Morphological opening node left aligned with Subtract Green Channel node. I Please help. Thanks!

share|improve this question
1  
About the overlapping boxes: see Difference between "right of=" and "right=of" in PGF/TikZ –  Torbjørn T. Dec 11 '13 at 23:21
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Martin Schröder Dec 11 '13 at 23:40
    
Related: Spanning multiple lines + text width for fixed length or Dependent node size in TikZ Overlapping. If you can improve your question/code with the answers from there, and you still need assistance, you can edit your question. –  Qrrbrbirlbel Dec 12 '13 at 0:57

2 Answers 2

up vote 11 down vote accepted

You can use positioning library and a useful reading will be this question. Further, tikzstyle is deprecated, use tikzset instead.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes.geometric}
\begin{document}
    \begin{tikzpicture}[>=latex']
        \tikzset{block/.style= {draw, rectangle, align=center,minimum width=2cm,minimum height=1cm},
        rblock/.style={draw, shape=rectangle,rounded corners=1.5em,align=center,minimum width=2cm,minimum height=1cm},
        input/.style={ % requires library shapes.geometric
        draw,
        trapezium,
        trapezium left angle=60,
        trapezium right angle=120,
        minimum width=2cm,
        align=center,
        minimum height=1cm
    },
        }
        \node [rblock]  (start) {Start};
        \node [block, right =2cm of start] (acquire) {Acquire Image};
        \node [block, right =2cm of acquire] (rgb2gray) {RGB to Gray};
        \node [block, right =2cm of rgb2gray] (otsu) {Localized OTSU \\ Thresholding};
        \node [block, below right =2cm and -0.5cm of start] (gchannel) {Subtract the \\ Green Channel};
        \node [block, right =2cm of gchannel] (closing) {Morphological \\ Closing};
        \node [block, right =2cm of closing] (NN) {Sign Detection \\ Using NN};
        \node [input, right =2cm of NN] (limit) {Speed \\ Limit};
        \node [coordinate, below right =1cm and 1cm of otsu] (right) {};  %% Coordinate on right and middle
        \node [coordinate,above left =1cm and 1cm of gchannel] (left) {};  %% Coordinate on left and middle

%% paths
        \path[draw,->] (start) edge (acquire)
                    (acquire) edge (rgb2gray)
                    (rgb2gray) edge (otsu)
                    (otsu.east) -| (right) -- (left) |- (gchannel)
                    (gchannel) edge (closing)
                    (closing) edge (NN)
                    (NN) edge (limit)
                    ;
    \end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks for the answer. Can you tell me how can I bring start at extreme left? –  Shivam Kalra Dec 12 '13 at 0:42
    
@ShivamKalra use \node [block, below right =2cm and -0.5cm of start] (gchannel) {Subtract the \\ Green Channel}; Use appropriate length for -0.5cm in below right =2cm and -0.5cm –  Harish Kumar Dec 12 '13 at 0:48
    
@Harrish Many thanks for answer. Please check my edits above. –  Shivam Kalra Dec 12 '13 at 1:44

As already mentioned Torbjørn, your problem is wrong use of right of = (deprecated use) and absent of library positioning. I suppose, that you like to achieve something like example below:

\documentclass[tikz,border=5mm]{standalone}
    \usetikzlibrary{arrows,positioning,shapes}
\begin{document}
    \begin{tikzpicture}[node distance=1cm,>=latex',
 block/.style = {draw, shape=rectangle, align=center},
rblock/.style = {draw, shape=rectangle, rounded corners=0.5em},
tblock/.style = {draw, shape=trapezium, trapezium left angle=60, 
                 trapezium right angle=120, align=center},
                        ]
\linespread{0.9}
    \node [rblock]                      (start)     {Start};
    \node [block, right=of start]       (acquire)   {Acquire Image};
    \node [block, right=of acquire]     (rgb2gray)  {RGB to Gray};
    \node [block, right=of rgb2gray]    (otsu)      {Localized OTSU\\ Thresholding};
    \node [block, below=of acquire]     (gchannel)  {Subtract the\\ Green Channel};
    \node [block, right=of gchannel]    (closing)   {Morphological\\ Closing};
    \node [block, right=of closing]     (detecting) {Sign Detectiing\\ using NN};
    \node [tblock, right=of detecting]  (speed)     {Speed\\ Limit};
\draw[->] (start) -- (acquire);
\draw[->] (acquire) -- (rgb2gray);
%etc
    \coordinate[below right=5mm and 5mm of otsu]   (a1);
    \coordinate[left=5mm of a1 -| gchannel.west]   (a2);
\draw[->] (otsu) -| (a1) -- (a2) |- (gchannel);
%etc
    \end{tikzpicture}
\end{document}

below is possible variant of desired flowchart (after your editing of question). i hope, that from all provided examples you will be able catch the principle, how to draw your flowchart. if you still have problems with width of picture, tray to use smaller fonts and schrink minimum width of boxes ...

\documentclass[tikz,border=5mm]{standalone}
    \usetikzlibrary{arrows,positioning,shapes}
\begin{document}
    \begin{tikzpicture}[node distance=4mm, >=latex',
 block/.style = {draw, rectangle, minimum height=10mm, minimum width=28mm,align=center},
rblock/.style = {draw, rectangle, rounded corners=0.5em},
tblock/.style = {draw, trapezium, minimum height=10mm, 
                 trapezium left angle=75, trapezium right angle=105, align=center},
                        ]
    \node [rblock]                      (start)     {Start};
    \node [block, right=of start]       (acquire)   {Acquire Image};
    \node [block, right=of acquire]     (rgb2gray)  {RGB to Gray};
    \node [block, below=of rgb2gray]    (otsu)      {Localized OTSU\\ Thresholding};
    \node [block, below=of acquire]     (gchannel)  {Subtract the\\ Green Channel};
    \node [block, below=of gchannel]    (closing)   {Morphological\\ Closing};
    \node [block, right=of closing]     (detecting) {Sign Detecting\\ using NN};
    \node [tblock, right=of detecting]  (speed)     {Speed\\ Limit};
%% paths (borowed from Harish Kumar)
    \path[draw,->] (start)      edge (acquire)
                   (acquire)    edge (rgb2gray)
                   (rgb2gray)   edge (otsu)
                   (otsu)       edge (gchannel)
                   (gchannel)   edge (closing)
                   (closing)    edge (detecting)
                   (detecting)  edge (speed)
                    ;
    \end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
You can add an image to see the output too. –  OSjerick Dec 11 '13 at 23:58
    
Thanks for the answer. –  Shivam Kalra Dec 12 '13 at 0:42
    
Please check my edits above. –  Shivam Kalra Dec 12 '13 at 1:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.