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.

I am trying to recreate the following image, as close as possible.


The point is that the circumference of the bottom, plus the height of the cube needs to be 30. Which gives

30 = 4x + h

so I want to be able to draw the cube where I vary the value of x. Below is what I have done so far





\begin{scope} [x     = {(\coeffReduc*\cost,-\coeffReduc*\sint)},
               y     = {(1cm,0cm)}, 
               z     = {(0cm,1cm)}]

\pgfmathsetmacro{\x}{5} \pgfmathsetmacro{\h}{30-4*\x}

\path coordinate (A) at (-\h/2,\x/2,\x/2) 
      coordinate (B) at (-\h/2,-\x/2,\x/2)
      coordinate (C) at (-\h/2,-\x/2,-\x/2)
      coordinate (D) at (-\h/2,\x/2,-\x/2)
      coordinate (A1) at (\h/2,\x/2,\x/2)
      coordinate (B1) at (\h/2,-\x/2,\x/2)
      coordinate (C1) at (\h/2,-\x/2,-\x/2)
      coordinate (D1) at (\h/2,\x/2,-\x/2)
      coordinate[label=$h$,left=0.65em] (M1) at ($ (B)!.5!(C) $)
      coordinate[label=$x$,below=2em] (M2) at ($ (C1)!.5!(C) $)
      coordinate[label=$x$,below=1.75em] (M3) at ($ (C1)!.5!(D1) $);

\fill [blue, fill opacity = 0.2]   (A)--(B)--(C)--(D) -- cycle;
\fill [blue, fill opacity = 0.3]   (C)--(D)--(D1)--(C1) -- cycle;
\fill [blue, fill opacity = 0.2]   (A1)--(B1)--(C1)--(D1) -- cycle;
\fill [blue, fill opacity = 0.2]   (B1)--(C1)--(C)--(B) -- cycle;
\fill [blue, fill opacity = 0.1]   (A1)--(D1)--(D)--(A) -- cycle;

\draw (A) -- (B) -- (C) -- (D) -- (A) -- (A1) -- (B1) -- (C1) -- (D1) -- (A1) ;
\draw (B) -- (B1) ; \draw (C) -- (C1) ; \draw (D) -- (D1) ;




My main problem, is that the code is very messy. And still does not quite do what I want it do do. I still having problems rotating the cube properly, The backlines are not shaded, and the whole coordinate thingy seems very messy and unproffesional. A tad smaller figure would also be much appreciated, I tried scaling the whole image, but alas this also shrank the labels.

Any tips suggestions to a better code, or ways to improve mine?

my attempt

share|improve this question
add comment

1 Answer

run with xelatex


\psset{Decran=15,viewpoint=20 20 50 rtp2xyz,lightsrc=viewpoint}
         a=\iX,b=a,c=30 a 4 mul sub,


enter image description here

share|improve this answer
There are times when pstricks seems to do things very easily. This one is a great example. Thanks. Oh, and +1 –  hpesoj626 Dec 7 '12 at 14:04
add comment

Your Answer


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.