13

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!

3

2 Answers 2

16

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

4
  • Thanks for the answer. Can you tell me how can I bring start at extreme left? Commented Dec 12, 2013 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 Commented Dec 12, 2013 at 0:48
  • @Harrish Many thanks for answer. Please check my edits above. Commented Dec 12, 2013 at 1:44
  • @HarishKumar I am sorry, but how can I edit this line (otsu.east) -| (right) -- (left) |- (gchannel) to connect between (otsu.south) and (gchannel.north) in down-left-down way? Commented Jun 4, 2016 at 18:23
8

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 as 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

Addendum: After twelve years ...

  • You can insert your diagram in figure* environment which span both columns
  • Or if you for some reason persist that flowchart should be placed just in one column, than you need to split it into three rows, reduce nodes font size and size inner xsep

Beside aforementioned at both cases the code is a bit shorter if you in image codes employ chains and its macro join, and ext.paths.ortho libraries:

\documentclass[twocolumn]{article} %--------------- show page layout. don't use in a real document! \usepackage{showframe} \renewcommand\ShowFrameLinethickness{0.15pt} \renewcommand*\ShowFrameColor{\color{red}} % \usepackage{lipsum} % for dummy text %---------------------------------------------------------------% %\documentclass[tborder=1mm]{standalone} \usepackage{stfloats} \usepackage{tikz} \usetikzlibrary{arrows.meta, chains, ext.paths.ortho, % defined in the tikz-ext package positioning, shapes} \begin{document} \begin{figure*}[ht] \centering \begin{tikzpicture} \makeatletter \tikzset{ node distance = 3mm and 11mm, start chain = going right, base/.style = {draw, semithick, align=center, inner sep=3pt, minimum height=9mm, font=\small\linespread{0.84}\selectfont}, block/.style = {base, minimum width=7.7em}, rblock/.style = {base, rounded corners=1ex}, tblock/.style = {base, shape=trapezium, trapezium left angle=60, trapezium right angle=120}, suspend join/.code={\def\tikz@after@path{}} % <--- } \makeatother \scoped[nodes={on chain, join=by ->}] { \node [rblock] (n0) {Start}; \node [block] (n1) {Acquire Image}; \node [block] (n2) {RGB to Gray}; \node [block] (n3) {Localized OTSU\\ Thresholding}; \scoped[nodes=suspend join] { \coordinate[below=of n1] (aux); \node [block, below=of aux] (n4) {Subtract the\\ Green Channel}; } \node [block] (n5) {Morphological\\ Closing}; \node [block] (n6) {Sign Detectiing\\ using NN}; \node [tblock] (n7) {Speed\\ Limit}; } % \draw[->] (n3) r-rl (aux) % <--- (aux) r-lr (n4); % [rl distance=17mm] \end{tikzpicture} \end{figure*} \lipsum[2-4] \end{document} 

enter image description here (red lines indicate page layout)

2
  • You can add an image to see the output too. Commented Dec 11, 2013 at 23:58
  • Please check my edits above. Commented Dec 12, 2013 at 1:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.