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 believe the following figure has been drawn very inefficiently. I need help drawing the same figure using nodes and relative positioning (right=of, below=of, ...etc) instead of using the absolute positioning.

This is my code:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{times}
\usepackage{tikz}

\usetikzlibrary{calc,decorations.markings,arrows,positioning,shapes}

\begin{document}

\begin{tikzpicture}[line width=1pt,>=latex',scale=0.8]

\node (d) at (-6,0) [draw,shape=rectangle,minimum width=8ex,minimum 
height=5ex,align=center]{Data\\source};

\draw (-4.5,2.5) rectangle node [align=center]{Partition \\ into blocks \\ and serial\\to parallel\\conversion} (-2,-2.5);

\draw (-1,2.5) rectangle node [align=center]{Division\\into\\subblocks} (1.5,-2.5);

\draw (2.5,1.5) rectangle node {IDFT} ++(1.5,1);
\draw (2.5,0) rectangle node {IDFT} ++(1.5,1);
\draw (2.5,-2.5) rectangle node {IDFT} ++(1.5,1);
\draw [->](d) -- (-4.5,0);
\draw [->](-2,0) -- node [above]{$D$}(-1,0);

\begin{scope}\fontsize{20}{19} \selectfont
\node at (2,-0.5) {$\vdots$};
\end{scope}

%% X-Circle 1
\begin{scope}
\node at (9.5,2) [above left]{$W_1$};
\draw [->] (6.4,2) -- (9.5,2);
\draw [->] (4,2) -- ++(1.6,0);
\node at (4.5,2) [above]{$b_1$};
\draw [fill] (4.5,2) circle (1.5pt);
\draw [->](4.5,2) --  (4.5,-3);
\draw [clip] (6,2) circle (0.4cm);
\draw (5.5,2.5) -- ++(1,-1);
\draw (5.5,1.5) -- ++(1,1);
\end{scope}

%% X-Circle 2

\begin{scope}
\node at (9.5,0.5) [above left]{$W_2$};
\draw [->] (4.0,0.5) -- ++(2.6,0);
\draw [->] (7.4,0.5) -- (9.5,0.5);
\node at (5.0,0.5) [above]{$b_2$};
\draw [fill] (5.0,0.5) circle (1.5pt);
\draw [->](5.0,0.5) -- (5,-3);
\draw [clip] (7,0.5) circle (0.4cm);
\draw (6.5,1) -- ++(1,-1);
\draw (6.5,0) -- ++(1,1);
\end{scope}

%% X-Circle 3
\begin{scope}
\node at (9.5,-2) [above left]{$W_{\! M}$};
\draw [->] (4,-2) -- ++(3.6,0);
\draw [->] (8.4,-2) -- (9.5,-2);
\node at (5.5,-2) [above]{$b_M$};
\draw [fill] (5.5,-2) circle (1.5pt);
\draw [->](5.5,-2) -- (5.5,-3);
\draw [clip] (8,-2) circle (0.4cm);
\draw (7.5,-1.5) -- ++(1,-1);
\draw (7.5,-2.5) -- ++(1,1);
\end{scope}

\draw (4,-3)rectangle node{Optimization for $W$} ++(4.5,-1);
\draw [->](6,-3) -- ++(0,4.6);
\draw [->](7,-3) -- ++(0,3.1);
\draw [->](8,-3) -- ++(0,0.6);
\draw (9.5,2.5)rectangle node{$+$} ++(1,-5);
\draw [->](10.5,0)-- node [above]{$S$}(11.2,0);

\begin{scope}\fontsize{20}{19} \selectfont
\node at (7.7,-0.5) {$\vdots$};
\end{scope}

\draw [->](1.5,2) -- ++(1,0);
\draw [->](1.5,0.5) -- ++(1,0);
\draw [->](1.5,-2.0) -- ++(1,0);

\end{tikzpicture}

\end{document}
share|improve this question

1 Answer 1

up vote 6 down vote accepted

Here is an almost complete rewrite. Since most of the stuff is repeated three times, you can take advantage of a foreach loop that each time draws one set of repated parts.

I got bored and skipped the remaining parts but I think you can take it from there

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,arrows,positioning}

\begin{document}
\begin{tikzpicture}[line width=1pt,>=latex',
               tall/.style={align=center,text width=2cm,minimum height=5cm},
               crossed/.style={circle,draw,minimum height=8mm,outer sep=0,path picture={\draw
               (path picture bounding box.south east) -- (path picture bounding box.north west)
               (path picture bounding box.south west) -- (path picture bounding box.north east);
                   }}]

\node (d) at (-6,0) [draw,align=center]{Data\\ source};
\node[draw,tall,right= of d] (e) {Partition into blocks and serial to parallel conversion} ;
\node[draw,tall,right= of e] (f) {Division into subblocks};
\node[draw,inner xsep=5mm] (op) at (6.25,-4) {Optimization for $W$};
\draw[->] (d) -- (e) -- (f);

\foreach \x[count=\xi] in {0.1,0.4,0.9}{
\draw node[draw,inner ysep=5pt]
    (idft-\xi) at ([xshift=2cm]$(f.north east)!\x!(f.south east)$) {IDFT}
    node[circle,inner sep=2pt,outer sep=0,fill,right=3mm + 5*\xi mm of idft-\xi,
         label={$\ifnum\xi=3b_M\else b_\xi\fi$}] (b-\xi){}
    node[crossed,right=1cm+\xi cm of idft-\xi] (c-\xi){};
\draw[->] (f.east|-idft-\xi) -- (idft-\xi);
\draw[->] (b-\xi) -- (b-\xi|-op.north);
\draw[<-] (c-\xi) -- (c-\xi|-op.north);
\draw[->] (idft-\xi) --(c-\xi);
}

\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
1  
Thanks a lot percusse, your solution helped me so much. One thing is still unclear to me which is how can I make the "(op)" node positioned relatively as the other nodes? The problem is when I try to scale the figure or change "node distance" I find this node dislocated. I appreciate your help. –  AboAmmar Jul 15 at 22:58
    
@AboAmmar You can place it relative to d,e, or f nodes to your liking with for example below right=3cm and -1cm of d etc. –  percusse Jul 16 at 10:38

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.