Typography with TeX and LaTeX

August 10th, 2008 by Stefan Kottwitz

With just a few lines of code you can create a drawing of a cube with a 3D impression, though if it’s not really perspective or raytraced:

\begin{tikzpicture}[on grid] \shade[yslant=-0.5,right color=gray!10, left color=black!50] (0,0) rectangle +(3,3); \draw[yslant=-0.5] (0,0) grid (3,3); \shade[yslant=0.5,right color=gray!70,left color=gray!10] (3,-3) rectangle +(3,3); \draw[yslant=0.5] (3,-3) grid (6,0); \shade[yslant=0.5,xslant=-1,bottom color=gray!10, top color=black!80] (6,3) rectangle +(-3,-3); \draw[yslant=0.5,xslant=-1] (3,0) grid (6,3); \end{tikzpicture}

This example uses the positioning tikz library.

Output screenshot:

By adding some slanted numbers we will get a Sudoku 3D cube:

TeX source code and pdf output are provided.

I’ve programmed it to answer a question posted on matheplanet.de. At first I wanted to use the matrix tikz library but it seemed to me that matrices of nodes cannot be slanted, at least I didn’t find a way.

This entry was posted on Sonntag, August 10th, 2008 at 22:38 and is filed under pgf/TikZ. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1. Kjell Magne Fauske said:

Nice cube! Can I add it to the TikZ and PGF gallery?

2. Stefan Kottwitz said: