# Tikz: Shading a rectangle diagonally,

I'm trying to draw a 3D picture with some shading to make it look a bit prettier. So far it's just a cuboid, and I discovered the shading command. Here is what I have so far:

\documentclass[varwidth, border=5pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}

\shade[bottom color=blue, top color = white] (0,0,0) -- (0.5,0,0) -- (0.5,2,0) -- (0,2,0) -- cycle;
\shade[bottom color=white, top color=blue] (0,2,0) -- (0,2,-2) -- (0.5,2,-2) -- (0.5,2,0) -- cycle;

\end{tikzpicture}
\end{document}


My problem is that defining shading angle=45 doesn't work. I can only get shading going from top to bottom, or left to right. Is there a way of defining the shading to go from one corner to another?

Thanks.

Edit: Maybe some technique using radial shading would work? But I'd need to be able to change the centre of the radial shading from the centre of the rectangle to the corner.

If I understand properly, you may use shadings library and say

\shade[lower left=blue, upper right=red] (0.5,0,0) -- (0.5,2,0) -- (0.5,2,-2) -- (0.5,0,-2) -- cycle;


I have chosen red just to make it conspicuous.

\documentclass[varwidth, border=5pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\begin{tikzpicture}

\shade[bottom color=blue, top color = white] (0,0,0) -- (0.5,0,0) -- (0.5,2,0) -- (0,2,0) -- cycle;
\shade[bottom color=white, top color=blue] (0,2,0) -- (0,2,-2) -- (0.5,2,-2) -- (0.5,2,0) -- cycle;
\shade[lower left=blue, upper right=red] (0.5,0,0) -- (0.5,2,0) -- (0.5,2,-2) -- (0.5,0,-2) -- cycle;

\end{tikzpicture}
\end{document}


A random colour choice gives

\documentclass[varwidth, border=5pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}

• Hi. Thanks for the answer, I'd forgotten about the shadings library. I've made it work with the following: \shae[lower right=red, upper left=red!20!white, lower left=red, upper right=red] etc.. – thosphor Jan 23 '15 at 15:16