# How to use shading in TikZ when rotating the picture?

I have the folloging problem: I wand to draw a rectangle and around, there should be some smooth fading to the background (white). I found the shading technique of tikz quite interesting. The problem is, that it does not behave as I suspect. See the following example:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw [color=red,xshift=2cm] (-1,-1) rectangle (1,1);
{ [ xshift=10cm,rotate=-30]
\filldraw [color=red,xshift=2cm] (-1,-1) rectangle (1,5);
}
\end{tikzpicture}
\end{document}


I for me get using pdflatex two blocks. The left is drawn corectly but (clearly) not rotated. In the right picture the colors at the ends of the fadings are not set correctly: I can see a difference between the white background and the nearly white upper left end. Also in the middle at the conjunction with the red square the color is not correct.

Can you tell me what I am doing wrong?

-

## migrated from stackoverflow.comDec 15 '11 at 19:08

The problem is that the figures get rotated first and then the shading is applied; to obtain the desided effect, you can apply a canvas transformation (See Section 22.4 Canvas Transformations of the pgf manual):

\documentclass{article}
\usepackage{tikz}

 Note that if you do this, you almost certainly want to still have shading angle=90 in the rotated block; as it stands, the code tries to rotate the shading 30° twice, and that gives the shading the odd "twisted" look it has in the picture. – Antal S-Z Dec 15 '11 at 22:09