Looking for a tikz-pgf solution to generate shapes with linear gradient fills that have multiple stops. So far I am able to get a single "stripe" with the following code snippet

    \draw (0,0) rectangle (5,1);
    \fill [left color=black,right color=black,middle color=white,shading angle=80] (0,0) rectangle (5,1);

which produces the following picture Bar with gradient fill produced with tikz

What I would like is an image with multiple gradient stops like the image below with the ability to vary the number of stops and their colors.

Multiple gradient stops


You can get shadings of this type with \pgfdeclarehorizontalshading.

color(2.5cm)=(white); color(3cm)=(black); color(3.5cm)=(white); 
 \draw[shading=bwbwb,shading angle=-20]  (0,0) rectangle (5,1);

enter image description here

| improve this answer | |
  • Thanks - that's perfect. – user2501235 May 13 at 15:07

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.