In the fading example at TikZ examples

I would like to change the "speed" at which fade occurs. In fact I would like it to be very "sharp" so that in the square examples you basically will see about half a square because it fades out so quick.

Any ideas how to achieve that? (basically I want to overlay two squares with different colors and end up seeing half a square of one color and the other half the other color but with a sort of quick fade between the two in the center(instead of the gradual fade that the default tikz setup gives)

  • I'd try using a fading (Section 20.3 of the PGF2.10 manual). You can create one from an arbitrary picture to do almost whatever you like. Mar 28, 2012 at 11:08

1 Answer 1


By default, there's no option for setting the transition speed between the colors of a linear shading. You can relatively easily add it, though. Here's a new style fading speed=<0..100> that allow setting the transition speed for the standard axis shading.

enter image description here


    fading speed/.code={

\begin{tikzpicture}[top color=blue, bottom color=yellow]

\foreach \speed [count=\count] in {0,25,...,100}{
    \fill [fading speed=\speed] (\count,0) rectangle +(1,2);
    \path (\count,0) +(0.5,2) node [text=white,anchor=north] {\speed};
  • 1
    cool, I didn't realize you could do these types of things.
    – Uiy
    Mar 28, 2012 at 12:46
  • Would it be possible to modify this so it takes into account the shading angle and initial direction? I would attempt to modify it myself but I don't quite understand the text macro ;/ I'm having issues with it since it uses a fixed direction and my code uses multiple directions(shades based on an angle that changes)
    – Uiy
    Mar 28, 2012 at 13:04
  • You can just set shading angle=<angle> to rotate the shading. Is that what you're looking for? Otherwise, it might be best to open a new question.
    – Jake
    Mar 28, 2012 at 13:08
  • This doesn't give the same effect as fading angle. I am using various fading angles and I want shading to work. I'm thinking it might not be your code as it does seem to change angles but happens to be the way things work. I'll open a new question for what I really want to do instead of creating tricks.
    – Uiy
    Mar 28, 2012 at 13:11

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.