I'm defining a shaded area that is offset from a origin coordinate, so that the whole of the drawing can be moved by only changing that single coordinate:

\coordinate (origin) at (0,0);
\shade [left color=blue, right color=red] (origin) ++ (90:0.4) ++ (170:1) --++ (90:0.6) --++ (0:0.2) --++ (-90:0.6) -- cycle;

I found out that the cycle completes the part of the rectangle that was drawn by the "pen", and not the offset that the pen moved before drawing, which was perfect for this.

But then the shading isn't working, and I guess it's because it's defining the gradient between origin (x=0) and the left edge of the rectangle, rather than between the left and right parts of the rectangle.

Is there a way of fixing my code so that the rectangle is shaded as one would be that wasn't offset?

1 Answer 1


If you add

\draw(current bounding box.north west) rectangle (current bounding box.south east);

you can see why this is happening.

enter image description here

Even though, you are not putting the pen down, you are modifying the bounding box which is used to stretch the underlying shading. There are more convenient options to perform such things for example moving a scope with everything in it

\usetikzlibrary{calc}% Just to be able to add points for the shift, not essential
\begin{scope}[shift={($(90:0.4)+(170:1)$)}]% or wherever you want to shift
\shade[left color=blue,right color=red](0,0)--++(90:0.6)--++(0:0.2)--++(-90:0.6)--cycle;
\draw(current bounding box.north west) rectangle (current bounding box.south east);

or you can move the initial coordinate origin around and move all the move-to operations to its definition.

  • Many thanks for the answer, you've described the situation perfectly. I've actually discovered the calc library since asking the question wherein one can modify coordinates like so ($ (origin) + (90:1) $) --++ (170:0.5) without moving the pen.
    – thosphor
    Nov 1, 2016 at 19:51
  • @user3087409 My pleasure
    – percusse
    Nov 1, 2016 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .