# Drawing a custom node and arrows in tikz

I am trying to draw the picture that I have drawn here in paint using tikz. I have managed to get this far (please see the code and the output diagram on the right hand side) but cannot quite get it to be what I want it to be (which is illustrated on the left hand side in the drawing in paint). Namely, there are three things I can't quite do:

1. Change the box around f to be the irregular quadrilateral rather than a rectangle.

2. Make the arrow going from the 'b bits' to the box around f not be diagonal and point to the left hand side of the box (rather than the top) but for the arrow not to merge with the arrow from 'l bits', and

3. I would like an arrow between two nodes that is dashed for the first half, and a standard arrow for the second half.

Any help/suggestions for how to do any one of these things would be greatly appreciated.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}

\begin{tikzpicture}
[nodes={draw, thick, fill=black!0}]

\node (fone) [rectangle, minimum width=1cm, minimum height=1cm] {$f$};
\node (xone) [draw=none,fill=none, above left=1cm and 0cm of fone] {$b$ bits};
\node (ktwo) [draw=none,fill=none, left of=fone, xshift=-1cm] {$\ell$ bits};
\node (ftwo) [draw=none, fill=none, right of=fone, xshift=1cm]{$\ell$ bits};

\draw [arrow] (xone) -- (fone);[![enter image description here][2]][2]
\draw [arrow] (ktwo) -- (fone);
\draw [arrow] (fone) -- (ftwo);

\end{tikzpicture}
\end{document}

• Can you please expand the code snippet that you have posted to a full minimal working example. This makes it much easier to help you, especially if there are hidden packages/libraries that are needed.A MWE should compile and be as small as possible to demonstrate your problem. – Andrew Sep 13 '16 at 15:18
• Apologies, I have now edited the code and it is a fully working example. – arthurmilton Sep 13 '16 at 15:39

A solution that does not require you to place everything with specific coordinates is as follows:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzstyle{arrow} = [thick,->,>=stealth]

\usetikzlibrary{shapes,shapes.multipart} % Required for the trapezoid shape
\usetikzlibrary{calc} % Required for the computation of the angle arrow

\begin{document}

\begin{tikzpicture}
% Draw the trapezium and rotate by 90 degrees. A rotation of the text is also needed
\node (fone) [draw,trapezium,trapezium left angle=70,trapezium right angle=0,rotate=-90,minimum width=1cm, minimum height=1cm] {\rotatebox{90}{$f$}};

% Inotrduce a coordinate to lean on for drawing the angle shape
\node[coordinate, left of=fone] (x) {};

\node (xone) [draw=none,fill=none, above of=x,node distance=1.5cm] {$b$ bits};
\node (ktwo) [draw=none,fill=none, left of=fone, xshift=-1cm] {$\ell$ bits};
\node (ftwo) [draw=none, fill=none, right of=fone, xshift=1cm]{$\ell$ bits};

% The following connects xone with the coordinate x at the exact point where
% fone has 245 degrees (Note that it was rotated by 90 deg), then draw the line.
\draw [arrow] (xone) |- ($(x.north east)!(fone.245)!(x.south east)$) |- (fone.245);
\draw [arrow] (ktwo) -- (fone);
\draw [arrow] (fone) -- (ftwo);

\end{tikzpicture}
\end{document}


The resulting scheme is the following:

• (+1) You're just missing dashing half the arrow on the right. One way of doing that would be \draw [thick,dashed] (fone) -- ($(fone)!0.5!(ftwo)$); \draw [arrow] ($(fone)!0.5!(ftwo)$) -- (ftwo); – Torbjørn T. Sep 13 '16 at 17:51
• Oh, I did not get that this was needed. Of course what you say works fine! Thanks! – aps Sep 13 '16 at 18:04

I find in these sort of situations it's often easier to take manual control of the position of everything

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}

\begin{tikzpicture}
[nodes={draw, thick, fill=black!0}]

\draw (1,0) -- (2,0) -- (2,1) -- (1,2) -- (1,0);
\node (fone) [draw=none,fill=none] at (1.5,.5) {$f$} ;
\node (xone) [draw=none,fill=none] at (.25,3) {$b$ bits};
\node (ktwo) [draw=none,fill=none] at (-1,.5) {$\ell$ bits};
\node (ftwo) [draw=none, fill=none] at (4,.5) {$\ell$ bits};

\draw [arrow] (ktwo) -- (1,.5);
\draw [dashed] (2,.5) -- (3,.5);
\draw [arrow] (3,.5) -- (ftwo);
\draw [arrow] (.25,1) -- (1,1);
\draw (xone) -- (.25,1);

\end{tikzpicture}
\end{document}

• That is exactly what I want, thank you so much. I notice though that the line from 'b bits' to 'f' looks to be slightly thinner than the line from 'l bits' to 'f', but I don't see anything in the code to differentiate the two thicknesses. Is there any way to alter this please? – arthurmilton Sep 13 '16 at 17:01
• @tatenda You should add thick to the two draw statements that are not styled by arrow: so, \draw[dashed, thick]...; and \draw[thick]...;. Similarly, you might want to change the thickness of the sides of the trapezium. – Andrew Sep 14 '16 at 0:32