# How to provide a mask highlighting an arrow tip over a cluttered background in Tikz?

I have a series of technical drawings that I use for background, highlighting features or adding dimensions and notes with Tikz. In some cases the background is very busy, and arrows tend to "disappear" in it. Using colors for arrows is not an option as the final technical brochure will be B/W. I am looking for an easy way to draw a white arrow tip over the background, slightly oversized compared to the normal arrow tip, in order to mask the background locally and enhance the (black) arrow tip visibility, drawn later. I have supplied a MWE to illustrate the context. In reality, the backgrounds I deal with are worse that in the MWE.

\documentclass[border= 5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns, arrows}
\begin{document}
\begin{tikzpicture}
\draw [step=0.1cm, pattern=north west lines] (-1,0) [very thick] rectangle (0.01, 3);
\draw [step=0.1cm, pattern=north west lines, very thick] (0,0) rectangle (1.42,1.4);
\draw [step=0.1cm, pattern=north east lines] (0,1.42) [very thick] rectangle (1.5,3);
\draw[] (-4.5,0)  -- (-2,0) node[above, midway, text width =2.3cm]{Clearance: 0,1 to 0,2 mm};
\draw[->, >= triangle 45] (-2,0)  -- (0.5,1.38);
\end{tikzpicture}
\end{document}


This isn't a particular automatic solution I'm afraid. It needs tweaking for your situation until it looks right.

• I draw a white thick line under your black line.
• Separately, I draw an arrow head at the right place.

It doesn't quite work to do those two steps together because the arrow head would be too big. The following page is a useful reference on how to adjust arrow head sizes: Is it possible to change the size of an arrowhead in TikZ/PGF?.

\documentclass[border= 5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns, arrows}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\draw [step=0.1cm, pattern=north west lines] (-1,0) [very thick] rectangle (0.01, 3);
\draw [step=0.1cm, pattern=north west lines, very thick] (0,0) rectangle (1.42,1.4);
\draw [step=0.1cm, pattern=north east lines] (0,1.42) [very thick] rectangle (1.5,3);
\draw[white, line width=1mm, shorten >=1mm]
(-4.5,0) -- (-2,0) -- (0.5,1.38);
\draw[->, >= triangle 45, white, decoration={
markings,mark=at position 1 with {
\arrow[xshift=0.7mm, scale=1.5]{>}}},
postaction={decorate}] (-2,0) -- (0.5,1.38);
\draw[->, >= triangle 45] (-4.5,0)
-- (-2,0)
node[above, midway, text width =2.3cm]{Clearance: 0,1 to 0,2 mm}
-- (0.5,1.38);
\end{tikzpicture}
\end{document}


• The improvement in visibility is significant. I did not consider masking also the arrow line, but I agree it helps. I could not find an easy way either. Having however very limited skills, as I am relatively new to LaTeX and Tikz, I thought perhaps there was some magic rescaling option that could do the job with a single keyword. – Yves Jun 8 '13 at 11:43
• Alternatively, you could simply add preaction={draw, white, line width=4pt, -},preaction={draw, white, ultra thick, shorten >=-2.5\pgflinewidth} to the \draw command to draw the line and arrow tip with a thick stroke underneath the black version. – Jake Jun 8 '13 at 11:56
• @Jake Is that supposed to have two preactions? – John Wickerson Jun 8 '13 at 11:59
• @JohnWickerson: Yeah, one's with and one's without the arrow tip (the one with -), because the line and arrow tip need different line thicknesses to look decent. – Jake Jun 8 '13 at 12:04
• @Jake I have no familiarity yet with the "postaction" and even less with the "preaction" features, but this option looks nice as the code is easy to read. – Yves Jun 8 '13 at 12:13

You can use a preaction to draw the line with a thick white stroke underneath the black line and arrow tip. If you wrap it in a style, you can say something like

\draw[halo,->, >= triangle 45] (-2,0)  -- (0.5,1.38);


to get

\documentclass[border= 5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns, arrows}

\tikzset{
halo/.style={
preaction={
draw,
white,
line width=4pt,
-
},
preaction={
draw,
white,
ultra thick,
shorten >=-2.5\pgflinewidth
}
}
}

\begin{document}
\begin{tikzpicture}
\draw [step=0.1cm, pattern=north west lines] (-1,0) [very thick] rectangle (0.01, 3);
\draw [step=0.1cm, pattern=north west lines, very thick] (0,0) rectangle (1.42,1.4);
\draw [step=0.1cm, pattern=north east lines] (0,1.42) [very thick] rectangle (1.5,3);
\draw[] (-4.5,0)  -- (-2,0) node[above, midway, text width =2.3cm]{Clearance: 0,1 to 0,2 mm};
\draw[halo,->, >= triangle 45] (-2,0)  -- (0.5,1.38);
\end{tikzpicture}
\end{document}

• Very nice, as it makes easier to re-use the solution a number of times and to adjust it in a single place. I had no idea either that this could be incorporated into a style... – Yves Jun 8 '13 at 12:49
• @Yves: That's one of the great things about TikZ, nearly everything can be wrapped in styles (John's solution, too). – Jake Jun 8 '13 at 12:51