I have gotten some undesirable behavior with PGF/TikZ related to clipping and drawing paths with different color, say gray. So I tried with no success to exchange between \clip[draw=gray], \draw[clip,gray] or \path[draw=gray, clip] or maybe using indirectly styles, the Emacs' output throws a TeX error message:

Extra options not allowed for clipping path command...

the only way to do so is by using scopes:

\begin{scope}[draw=gray] ... \end{scope}

Unfortunately, this technique requires that all the scoped objects' lines should be switched to black. So is there a trickery way to achieve this without passing by scope environment?


The clip command in tikz is not made to actually draw a path, it is meant to delimit to region. That is why the drawing option don't work with it. The error message

Extra options not allowed for clipping path command...

you were getting is saying exactly that.

However, if you still want to draw along the clipping path, it is possible, by using a preaction or a postaction.

When a path command contains the preaction option it takes the same path and does things before the main path is created. For example, if you use the command

\path[clip,preaction = {draw=red,ultra thick}] (0,0) circle[radius=1];

will use the circle to clip any of the following commands, but before that it will draw the circle with a red and ultra thick line.

| improve this answer | |

From a user's point of view, the difficulty with simultaneously clipping and drawing a path is that these two operations are not commutative, and there is no obvious order to apply. Contrast this with drawing and filling: again, the two operations are not commutative but it is fairly clear that one should fill and then draw.

So the program doesn't allow draw-with-clip, at least so long as the command to draw-and-clip is explicit enough for it to detect it. Rather, you have to use a solution such as Frederic's where you must explicitly declare whether you want to draw first and clip after or the other way around (by either interchanging the clip and draw or by using a postaction instead of a preaction).

Incidentally, drawing along the same path as the clip is a neat solution to the problem of drawing on one side of a line. I've used that somewhere here ...

Here's a bit of code to help illustrate the above:


\begin{tikzpicture}[line width=3mm]
\path[clip, preaction={draw}] (0,0) circle[radius=2cm];
\path[clip, postaction={draw}] (5,0) circle[radius=2cm];

clipped and drawn paths (revised version)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.