# Drawing “bus width”-like markers with number on arrows

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

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.

• I think you can use the decoration in this one tex.stackexchange.com/questions/51022/… Can it be a duplicate? – percusse Jul 25 '13 at 18:13
• Thank you for pointing me to the other question. It provides a useful hint towards decorations but is a bit more specific in terms of commutative diagrams. I think the answer by Gonzalo Medina is precisely what I need in my case because it also includes the numbers. – Rob Jul 25 '13 at 18:38
• Is the number 4 part of the slash or is it independent of it? And is it always a 4? – Qrrbrbirlbel Jul 26 '13 at 7:40

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}


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);

• Thank you very much for the full example and thanks for fixing the arrows :) I forgot to mention that I had previously asked about the arrows in a separate question tex.stackexchange.com/questions/125459/… but both solutions for the arrow problems work fine. Thanks again! – Rob Jul 25 '13 at 18:37
• can you include my comment in the linked question to this so that we can close the other one please? – percusse Jul 25 '13 at 18:57
• @percusse done! – Gonzalo Medina Jul 25 '13 at 19:01

There is actually a \BusWidth symbol in the milstd package. How it might be used in your application could be given below. I don't know tikz, or I'd thicken up the dashed lines to match the thickness of the scaled \BusWidth.

The nice thing about the 45 degree inclination is that it can be used on vertical wires, as well. Of course, in that case, you would want to stick the bus width off to the side. Something similar was asked at Bussymbol for tikz circuit lib.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{milstd}
\usepackage{stackengine}
\newcommand\Bussymbol[1]{%
\raisebox{-1.1em}{\scalebox{.7}{\stackunder{\BusWidth}{#1}}}%
}
\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}
]
\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)$) {\Bussymbol{4}};
\draw [->,dashed,dash pattern=on 1pt off 1pt] (delta.-58.75) -- (al);
\node at ($(al) - (0.55, 0)$) {\Bussymbol{4}};
\end{tikzpicture}

\end{document}


I happened to need this recently myself. Here is what I use:

  \newcommand{\buswidth}[4][]{\draw (#2) node [#4=.6ex,#1] {#3} +(45:-.8ex) -- +(45:.8ex)}

% usage:  \buswidth{<coordinate>}{<label>}{<left|right>};
% Example:
\buswidth{p1}{$x$}{left}


It's not terribly generic, but it can be tweaked easily to your liking.