Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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.

share|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:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/42714/86}
\usepackage{tikz}

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

clipped and drawn paths (revised version)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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