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.

With PGF/TikZ one can produce fadings, like

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
    \fill[green,path fading=south] (90:4) -- (210:4) -- (-30:4) -- cycle;
\end{tikzpicture}
\end{document}

fading example

Now I would like to rotate this picture by 120°, so that the fading starts at the left corner. TikZ has a fading angle key, so that I thought the following should work:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
    \fill[green,path fading=south, fading angle=120] (90:4) -- (210:4) -- (-30:4) -- cycle;
\end{tikzpicture}
\end{document}

To my surprise, this produces the following picture:

rotated fading

Note that the fading doesn't start immediately at the corner and doesn't fade all the way to white (the upper vertex is at 25% saturation and the right one at 33%).

What is going on here and how can I produce the correct rotated picture?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

The thing to remember about fadings is that they work by putting a rectangle behind the object, fading the rectangle and then clipping to the object. If you fade a rectangle with fade angle=120 then you'll see that it does get to white, but only in the upper right corner of the rectangle, which isn't seen by the triangle.

One way to get the fading to rotate correctly is to apply a canvas transformation. Of course, this can get a bit tricky working out all the coordinates! But as you can see below, this does work.

The images below are:

  1. The triangle rotated using a coordinate transformation (this one is first so I don't have to worry about the origin of rotation!) so the special options are transform canvas={rotate=120},path fading=south.
  2. The result of putting just rotate=120: viz, the triangle is rotated but the fading isn't.
  3. The original: path fading=south
  4. The rotated fading: path fading=south,fading angle=120
  5. The rectangular version of that, showing that the fading does fade to white

tikz fadings

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.