[Tex/LaTex] Drawing “bus width”-like markers with number on arrows

arrowstikz-pgf

I'm trying to draw arrows with / marks and numbers like in the following picture:

screenshot of the arrows with / marks

My current solution looks like this:

\begin{tikzpicture}
    [
        inverter/.style={rectangle,draw,inner sep=2pt,minimum size=6mm},
        dot/.style={circle,inner sep=0pt,minimum size=0.5mm,draw,fill=black}
    ]
    \node (x) at (0,0) {$x$};
    \node (delta) at (1,0) [shape=rectangle,draw,minimum height=18mm,minimum width=6mm] {$\delta$};

    \node(ah)     at ( 2,  0.5) [inverter] {$a_h$};
    \node(al)     at ( 2, -0.5) [inverter] {$a_l$};

    \draw [->] (x) -- (delta);

    \draw [->,dashed,dash pattern=on 1pt off 1pt] (delta.58.75) -- (ah);
    \node at ($ (ah) - (0.55, 0) $) {\scriptsize /};
    \node at ($ (ah) - (0.5, 0.2) $) {\tiny 4};
    \draw [->,dashed,dash pattern=on 1pt off 1pt] (delta.-58.75) -- (al);
    \node at ($ (al) - (0.55, 0) $) {\scriptsize /};
    \node at ($ (al) - (0.5, 0.2) $) {\tiny 4};
\end{tikzpicture}

which is pretty hacky and doesn't look nice. I tried strike out shapes but found the line to be much too long. However, positioning a / and a number manually seems like a pretty bad solution to me. I've seen a similar question that revolved around striking out lines or arrows, but without any numbering. Any input would be most welcome.

Best Answer

As percusse mentions in his comment, adding the slash can be done using a decoration (in this case, using the decorations.markings library); the number (if it's not part of the decoration) can be added in the path, using a node; something like:

\draw (<coord1>) -- node[below] {<text>} (<coord2>);

I also fixed the dashed arrows using the perpendicular coordinate system to guarantee that they are horizontal.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings}

\begin{document}

\begin{tikzpicture}[
inverter/.style={rectangle,draw,inner sep=2pt,minimum size=6mm},
dot/.style={circle,inner sep=0pt,minimum size=0.5mm,draw,fill=black},
decoration={
  markings,
  mark= at position 0.5 with {\node[font=\footnotesize] {/};}
  }
]
\node (x) at (0,0) {$x$};
\node (delta) at (1,0) [shape=rectangle,draw,minimum height=18mm,minimum width=6mm] {$\delta$};
\node (ah)  at ( 2,  0.5) [inverter] {$a_h$};
\node (al)   at ( 2, -0.5) [inverter] {$a_l$};

\draw [->] (x) -- (delta);
\draw [->,dashed,dash pattern=on 1pt off 1pt,postaction={decorate}] (delta.58.75) -- node[below=1pt] {\tiny 4} (ah.west|-delta.58.75);
\draw [->,dashed,dash pattern=on 1pt off 1pt,postaction={decorate}] (delta.-58.75) -- node[below=1pt] {\tiny 4} (al.west|-delta.-58.75);
\end{tikzpicture}

\end{document}

enter image description here

As suggested by percusse, another, perhaps better way, to use the perpendicular coordinate system to have the arrows horizontal is to use:

\draw [->,dashed,dash pattern=on 1pt off 1pt,postaction={decorate}] (delta.east|-ah) -- node[below=1pt] {\tiny 4} (ah);
\draw [->,dashed,dash pattern=on 1pt off 1pt,postaction={decorate}] (delta.east|-al) -- node[below=1pt] {\tiny 4} (al);