Some issues in positioning arrows and labeling them

I want to draw something like this.

But I am able draw this things:

So there are three problems:

1. Input and output arrows not positioned properly.
2. I want a rectangle above 5 X 1 MUX text.
3. I am not able to position text properly inside a block. Like I want x in front of every arrow.

I am attaching my tex code

\begin{tikzpicture}[thick]

\node [input, name=input] {};
\node [block, right of=input,minimum width=3cm, minimum height=2.5cm,node distance=0.5cm] (a) {Frame Encoder};
\node [block, right of=a,minimum width=3cm, minimum height=5cm,node distance=5cm] (b) {};
\node [block, right of=b, pin={[pinstyle]above:Ack},minimum width=3cm, minimum height=5cm,node distance=5cm] (c) {$5$ $\times$ $1$ MUX};
\node [output,right of=c] (output) {};

\begin{scope}[->,>=latex]

\draw[->] (input) -- (a);
\draw[->] (c) -- (output);
\foreach \i in {-2,...,2}{%
\draw[->] ([yshift=\i * 0.4 cm]a.east) -- ([yshift=\i * 0.8 cm]b.west) ;}

\foreach \i in {-2,...,2}{%
\draw[->] ([yshift=\i * 0.8 cm]b.east) -- ([yshift=\i * 0.8 cm]c.west) ;}

\end{scope}
\end{tikzpicture}


Thanks a lot for the help. My most of the problems got resolved. There is only one problem now. I want this x's to be numbered. For that, I am using count as some suggested. But now it doesn't compile. What mistake am I making?

\begin{tikzpicture}[thick]
\tikzset{input/.style={}}
\tikzset{block/.style={rectangle,draw}}
\tikzstyle{pinstyle} = [pin edge={to-,thick,black}]

\node [input, name=input] {};
\node [block, right=1cm of input,minimum width=3cm, minimum height=2.5cm] (a) {Frame Encoder};
\node [block, right of=a,minimum width=3cm, minimum height=5cm,node distance=5cm] (b) {};
\node [block, right of=b, pin={[pinstyle]above:Ack},minimum width=3cm, minimum height=5cm,node distance=5cm] (c) {$5$ $\times$ $1$ MUX};
\node [right =1cm of c] (output) {};

\begin{scope}[->,>=latex]

\draw[->] (input) -- (a);

\node at (b.center) {\footnotesize{z}};

\draw[above] ($(c.text)+(0,1)$)rectangle ($(c.text)+(1.85,2)$);

\draw[->] (c) -- (output);

\foreach \i [count=\xi]in {2,...,-2}{%
\draw[->] ([yshift=\i * 0.4 cm]a.east) -- ([yshift=\i * 0.8 cm]b.west) node[right]{\footnotesize{$x_{\xi}$}} ;}

\foreach \i in {-2,...,2}{%
\draw[->] ([yshift=\i * 0.8 cm]b.east) -- ([yshift=\i * 0.8 cm]c.west) ;}

\end{scope}
\end{tikzpicture}

-
While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. This is especially true with tikz as there are numerous packages. – Peter Grill May 27 '12 at 6:49
you can remove -> in the last scope for all the commands \draw it's an option of the scope ! and you can add some graphic parameters in the style block – Alain Matthes May 27 '12 at 9:48

1) Input and output arrows not positioned properly :

It's normal here because by default right of=input places a node at 1 cm to the right of (input) but the width of your new node given by minimum width=3cm is 3 cm. (input) is inside the new node. You make the same mistake for (output). You can use the library positioning with right=3cm of input or you can use 'anchor=west.

2) You get a rectangle with the use of (c.center) and a yshift

3) For the text, the question is unclear

Here a solution if the picture needs a scale action

\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{calc,positioning} no it's not useful
\begin{document}

\begin{tikzpicture}[thick,scale=.8]
\tikzset{input/.style={}} % <= this can be avoided but then use simply \node[name=input]{};
\tikzset{block/.style={rectangle,fill=blue!15,draw,anchor=west,minimum width=3cm,minimum height=5cm}} % to avoid some repetitions
\node [input, name=input] {};
\node [block, minimum height=2.5cm] (a) at ([xshift=1cm]input) {Frame Encoder};
\node [block ] (b) at ([xshift=4cm]a) {};
\node [block, right of=b, pin={above:Ack}] (c) at ([xshift=4cm]b) {$5$ $\times$ $1$ MUX};
\node  (output) at ([xshift=3cm]c)  {};
\node [draw,minimum height =1cm,minimum width=1.85cm,below=.5cm] at (c.north)  {};
\node at (b.center) {\footnotesize{z}};

\begin{scope}[->,>=latex]
\draw (input) -- (a); % I remove  -> because it's an option of the scope !
\draw (c) -- (output); % idem

\foreach \i [count=\xi] in {-2,...,2}{% remove  ->
\draw ([yshift=\i * 0.4 cm]a.east) -- ([yshift=\i * 0.8 cm]b.west)
node[right]{\footnotesize{$x_\xi$}} ;}

\foreach \i in {-2,...,2}{% remove  ->
\draw ([yshift=\i * 0.8 cm]b.east) -- ([yshift=\i * 0.8 cm]c.west) ;}

\end{scope}
\end{tikzpicture}

\end{document}


-
One small doubt : How do I write x_1, x_2, ..., x_5 instead of x? – tikzlearner May 27 '12 at 10:19
I modify my answer for your request. I used [count=\xi] – Alain Matthes May 27 '12 at 13:58
Thanks a lot :) – tikzlearner May 28 '12 at 6:46

The pinstyle, as all others styles are not given in your question so I declared just important ones.

The code is:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}
\begin{tikzpicture}[thick]
\tikzset{input/.style={}} % <= this can be avoided but then use simply \node[name=input]{};
\tikzset{block/.style={rectangle,fill=blue!15,draw}}
\node [input, name=input] {};
\node [block, right=1cm of input,minimum width=3cm, minimum height=2.5cm] (a) {Frame Encoder};
\node [block, right of=a,minimum width=3cm, minimum height=5cm,node distance=5cm] (b) {};
\node [block, right of=b, pin={[]above:Ack},minimum width=3cm, minimum height=5cm,node distance=5cm] (c) {$5$ $\times$ $1$ MUX};
\node [right =1cm of c] (output) {};

\begin{scope}[->,>=latex]

\draw[->] (input) -- (a);

% text in the center of the block b
\node at (b.center) {\footnotesize{z}};

% a rectangle in the c block
\draw[above] ($(c.text)+(0,1)$)rectangle ($(c.text)+(1.85,2)$);

\draw[->] (c) -- (output);
\foreach \i in {-2,...,2}{%
\draw[->] ([yshift=\i * 0.4 cm]a.east) -- ([yshift=\i * 0.8 cm]b.west) node[right]{\footnotesize{x}} ;} %<= this to place x in front of each arrow

\foreach \i in {-2,...,2}{%
\draw[->] ([yshift=\i * 0.8 cm]b.east) -- ([yshift=\i * 0.8 cm]c.west) ;}

\end{scope}
\end{tikzpicture}

\end{document}


Explanation

• For input and output you can avoid to declare a style that actually is empty (in the code you will find a comment on that).

• To place a z exactly in the center of a block you can use simply:

\node at (b.center) {\footnotesize{z}};

for all keys available please refer to the pgfmanual 48.2 Predefined Shapes - rectangle.

• To insert x in front of each arrow, it is possible to place a node with the text after the \draw in your foreach.

• Finally, to place the rectangle above the text, I prefer using the calc library rather than yshift as Altermundus suggested. Moreover I started from c.text instead of c.center.

EDIT

To insert numbered x, change the \foreach into:

\draw[->] (c) -- (output);
\foreach \i [count=\xi]in {2,...,-2}{%
\draw[->] ([yshift=\i * 0.4 cm]a.east) -- ([yshift=\i * 0.8 cm]b.west) node[right]{\footnotesize{$x_{\xi}$}} ;}


to have numbers that starts from the top or:

\draw[->] (c) -- (output);
\foreach \i [count=\xi]in {-2,...,2}{%
\draw[->] ([yshift=\i * 0.4 cm]a.east) -- ([yshift=\i * 0.8 cm]b.west) node[right]{\footnotesize{$x_{\xi}$}} ;}


from the bottom. The first solution gives:

-
I prefer c.center or c.north because it's a central point. c.center is interesting only if the dimensions of the rectangle depends of the text but in this case you need to use the width of the text. Then I think it's preferable to use a node to draw the rectangle. It's more coherent because all the shapes come from nodes. Then with right= of is a problem if you want to scale the picture. I give another solution with the possibility of scaling. – Alain Matthes May 27 '12 at 9:38
One small doubt : How do I write x_1, x_2, ..., x_5 instead of x? – tikzlearner May 27 '12 at 9:41
@Altermundus: you are right that my solution doesn't allow the scaling, but I thought that the OP had in mind a fixed image with dimensions already given. – Claudio Fiandrino May 27 '12 at 9:48
@ClaudioFiandrino Yes it's possible but I always avoid the use of positioning, because I think it's more easy to adjust and I discovered TikZ when positioning doesn't exist !! With positioning the distance depends of node distanceand for the syntax, the only advantage of positioning` is right or left are more explicit for some users. – Alain Matthes May 27 '12 at 9:54
The edited part is not working. What is this count? – tikzlearner May 27 '12 at 9:59