# TikZ: Using a line with thickness as clipping region?

In TikZ, is it possible to clip away a line? I would like to create a thin layer around an arrow in which nothing should be drawn (i.e. keep what is there at the moment the arrow is drawn) to create the feeling that the arrow lies above all shapes that are drawn there afterwards. I have figured that I want to clip away a region that looks like the arrow but is just a bit thicker in order to get the effect that I want. How can I achieve that?

-
I don't think this will work, since only the centerline of a thick line is used for determining the clipping boundary. – Jake Aug 2 '13 at 4:39

## 1 Answer

Try something like this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{invclip/.style={clip,insert path={{[reset cm]
(-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)
}}}}

\begin{document}
\begin{tikzpicture}
\filldraw[green](1,0)circle(3);
\filldraw[red](1,-0.5)rectangle(2,2);
\coordinate(A) at (0,0);

\draw[->,line width=2pt](A)-+(50:3)coordinate(B);
\begin{pgfinterruptboundingbox}
\path[invclip]($(A)+(-40:0.1)$)--($(B)+(-40:0.1)$)--($(B)+(-40:-0.1)$)--($(A)+(-40:-0.1)$)--cycle;
\end{pgfinterruptboundingbox}

\filldraw[blue](0,0)rectangle(1,1);
\end{tikzpicture}
\end{document}


I've used the negative clipping from here: How can I invert a 'clip' selection within TikZ?

What you need to do:

Define a macro which automates this part:

\draw[->,line width=2pt](A)-+(50:3)coordinate(B);
\begin{pgfinterruptboundingbox}
\path[invclip]($(A)+(-40:0.1)$)--($(B)+(-40:0.1)$)--($(B)+(-40:-0.1)$)--($(A)+(-40:-0.1)$)--cycle;
\end{pgfinterruptboundingbox}


Exact implementation depends on the way you define your coordinates.

Here's a (not very sophisticated) example:

\newcommand{\clipVect}[4]{
\draw[->,line width=#4](#1)-+(#2:#3)coordinate(B);
\begin{pgfinterruptboundingbox}
\path[invclip]($(#1)+(#2-90:#4pt)$)--($(B)+(#2-90:#4pt)$)--($(B)+(#2+90:#4pt)$)--($(A)+(#2+90:#4pt)$)--cycle;
\end{pgfinterruptboundingbox}}
\clipVect{A}{50}{3}{2}


The first argument is the starting point of the vector, the second the direction (in degree), 3rd argument ist the length and the 4th is the line width.

[Also currently the clipping is a little broken (it clips away everything which isn't in the 1st quadrant - that can be fixed i guess but currently i haven't got the time to do it myself.] Ignore this - i think i've fixed it (by copying the other answer in the previously linked question).

-