TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the following example:

\shade[bottom color=cyan!60!black, top color=red, middle color = blue!20!white] (0,0) rectangle (4,5);

Is it possible to instead of having the 'middle color' being in the middle of the rectange but to shift it say up by a quarter so that the 'middle color' separates the 'top' and 'bottom' color at three quarters of the way up?

share|improve this question
You can fake it using twice \shade[bottom color=cyan!60!black, top color=red, middle color = blue!20!white] (0,0) rectangle (4,5); and changing the coordinates to produce two shades one above the other. – Sigur Jul 16 '14 at 14:15
changing what coordinates? – KatyB Jul 16 '14 at 14:18
The rectangle coordinates. – Sigur Jul 16 '14 at 14:24
I was looking for a solution that could also be used for other shapes such as circles or more complicated shapes. – KatyB Jul 16 '14 at 14:26
@KatyB You can use Sigur's solution combined with clip for other shapes. – JLDiaz Jul 16 '14 at 14:34
up vote 9 down vote accepted

Yes, it is possible. In this answer I will try to cover the vertical shading: the concepts can be applied in the same way to the horizontal shading. Radial shading, instead is a bit different and the idea has been already implemented in TikZ: radial shading of a ring to some extent.

The code:


\tikzset{vertical custom shading/.code={%
  color(\tikz@vcs@bottom bp)=(tikz@axis@bottom);
  color(\tikz@vcs@middle bp)=(tikz@axis@middle);
  color(\tikz@vcs@top bp)=(tikz@axis@top);


\draw[top color=red,
      bottom color=blue, 
      middle color=white,
      vertical custom shading=60]
 (0,0) rectangle (4,2);

\draw[top color=blue,
      bottom color=red, 
      middle color=white,
      vertical custom shading=35]
 (5,0) rectangle (9,2);


The result:

enter image description here

share|improve this answer
Nice! So easy to understand the theory behind the codes. Math!! – Sigur Jul 16 '14 at 15:11
@Sigur: Indeed, you always need some math for drawings. :) – Claudio Fiandrino Jul 17 '14 at 6:23

Your Answer


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.