7

I am trying to make digits from unit cubes in tikz. This is number six, and there is an error, as you will see. How to correct thisenter image description here?

\documentclass[oneside]{standalone}
\usepackage{amssymb, latexsym, amscd, amsthm, amsmath}

\usepackage{tikz}
\usetikzlibrary{calc,decorations,decorations.pathmorphing}

\newcommand{\tikzcuboid}[4]{% width, height, depth, scale
\begin{tikzpicture}[scale=#4]
\foreach \x in {0,...,#1}
{   \draw (\x ,0  ,#3 ) -- (\x ,#2 ,#3 );
    \draw (\x ,#2 ,#3 ) -- (\x ,#2 ,0  );
}
\foreach \x in {0,...,#2}
{   \draw (#1 ,\x ,#3 ) -- (#1 ,\x ,0  );
    \draw (0  ,\x ,#3 ) -- (#1 ,\x ,#3 );
}
\foreach \x in {0,...,#3}
{   \draw (#1 ,0  ,\x ) -- (#1 ,#2 ,\x );
    \draw (0  ,#2 ,\x ) -- (#1 ,#2 ,\x );
}
\end{tikzpicture}
}

\newcommand{\drawbox}[4]{
    \pgfmathsetmacro \angle {30}
    \pgfmathsetmacro \xd {{2/3*cos(\angle)}}
    \pgfmathsetmacro \yd {{2/3*sin(\angle)}}
    \pgfmathsetmacro \x {{#1-1+(#2-1)*(\xd)}}
    \pgfmathsetmacro \y {{#3-1+(#2-1)*(\yd)}}

    \draw[fill=#4] (\x,\y) -- (\x+1,\y) -- (\x+1,\y+1) -- (\x,\y+1) -- cycle;
    \draw[fill=#4] (\x,\y+1) -- (\x+\xd,\y+1+\yd) -- (\x+1+\xd,\y+1+\yd) -- (\x+1,\y+1) -- cycle;
    \draw[fill=#4] (\x+1,\y+1) -- (\x+1+\xd,\y+1+\yd) -- (\x+1+\xd,\y+\yd) -- (\x+1,\y) -- cycle;
}



   \begin{document}


\begin{tikzpicture}[rotate=.8512, scale=.352830487, line width=.673pt]
        \drawbox{2}{3}{-1}{blue!21} 
 \drawbox{2}{3}{-3}{blue!21} 
 \drawbox{2}{3}{-2}{blue!21} 
 \drawbox{2}{3}{-1}{blue!21} 

\drawbox{2}{3}{0}{blue!21} 
    \drawbox{2}{3}{1}{blue!21}

    \drawbox{3}{3}{1}{blue!21}
        \drawbox{4}{3}{1}{blue!21}
      \drawbox{5}{3}{1}{blue!21}
                \drawbox{6}{3}{1}{blue!21}        
\drawbox{3}{3}{-3}{blue!21}
\drawbox{4}{3}{-3}{blue!21}
\drawbox{5}{3}{-3}{blue!21}

\drawbox{2}{3}{-7}{blue!21} 
\drawbox{2}{3}{-6}{blue!21} 


\drawbox{3}{3}{-7}{blue!21} 
\drawbox{4}{3}{-7}{blue!21} 
\drawbox{5}{3}{-7}{blue!21} 
\drawbox{6}{3}{-7}{blue!21}
\drawbox{6}{3}{-6}{blue!21} 
 \drawbox{6}{3}{-5}{blue!21} 

\drawbox{6}{3}{-4}{blue!21} 
\drawbox{6}{3}{-3}{blue!21} 


\drawbox{2}{2}{-5}{blue!21} 

\drawbox{2}{3}{-4}{blue!21} 
\drawbox{2}{3}{-5}{blue!21} 

\drawbox{2}{2}{-4}{blue!21} 


\drawbox{2}{2}{-5}{blue!21} 

\drawbox{2}{3}{-4}{blue!21} 
\drawbox{2}{2}{-4}{blue!21} 


          \drawbox{2}{2}{-1}{blue!21} 
 \drawbox{2}{2}{-3}{blue!21} 
 \drawbox{2}{2}{-2}{blue!21} 
 \drawbox{2}{2}{-1}{blue!21} 

\drawbox{2}{2}{0}{blue!21} 
    \drawbox{2}{2}{1}{blue!21}

    \drawbox{3}{2}{1}{blue!21}
        \drawbox{4}{2}{1}{blue!21}
        \drawbox{5}{2}{1}{blue!21}
                \drawbox{6}{2}{1}{blue!21}        
\drawbox{3}{2}{-3}{blue!21}
\drawbox{4}{2}{-3}{blue!21}
\drawbox{5}{2}{-3}{blue!21}
\drawbox{6}{2}{-3}{blue!21} 


\drawbox{2}{2}{-7}{blue!21} 
\drawbox{2}{2}{-6}{blue!21} 



\drawbox{3}{2}{-7}{blue!21} 
\drawbox{4}{2}{-7}{blue!21} 
\drawbox{5}{2}{-7}{blue!21} 
\drawbox{6}{2}{-7}{blue!21}
\drawbox{6}{2}{-6}{blue!21} 
 \drawbox{6}{2}{-5}{blue!21} 

\drawbox{6}{2}{-4}{blue!21} 
\drawbox{6}{2}{-3}{blue!21} 


\end{tikzpicture}

\end{document}
  • What's the point of oneside with standalone? – cfr Dec 7 '17 at 4:13
  • I modified from an old article and forget deleting it. – Thumbolt Dec 7 '17 at 4:21
8

You just have the order slightly wrong:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\newcommand{\drawbox}[4]{
  \pgfmathsetmacro \angle {30}
  \pgfmathsetmacro \xd {{2/3*cos(\angle)}}
  \pgfmathsetmacro \yd {{2/3*sin(\angle)}}
  \pgfmathsetmacro \x {{#1-1+(#2-1)*(\xd)}}
  \pgfmathsetmacro \y {{#3-1+(#2-1)*(\yd)}}
  \draw[fill=#4] (\x,\y) -- (\x+1,\y) -- (\x+1,\y+1) -- (\x,\y+1) -- cycle;
  \draw[fill=#4] (\x,\y+1) -- (\x+\xd,\y+1+\yd) -- (\x+1+\xd,\y+1+\yd) -- (\x+1,\y+1) -- cycle;
  \draw[fill=#4] (\x+1,\y+1) -- (\x+1+\xd,\y+1+\yd) -- (\x+1+\xd,\y+\yd) -- (\x+1,\y) -- cycle;
}
\begin{document}
  \begin{tikzpicture}[rotate=.8512, scale=.352830487, line width=.673pt,join=round]
    \drawbox{2}{3}{-1}{blue!21} 
  \drawbox{2}{3}{-3}{blue!21} 
  \drawbox{2}{3}{-2}{blue!21} 
  \drawbox{2}{3}{-1}{blue!21} 

  \drawbox{2}{3}{0}{blue!21} 
  \drawbox{2}{3}{1}{blue!21}

  \drawbox{3}{3}{1}{blue!21}
  \drawbox{4}{3}{1}{blue!21}
  \drawbox{5}{3}{1}{blue!21}
  \drawbox{6}{3}{1}{blue!21}        
  \drawbox{3}{3}{-3}{blue!21}
  \drawbox{4}{3}{-3}{blue!21}
  \drawbox{5}{3}{-3}{blue!21}

  \drawbox{2}{3}{-7}{blue!21} 
  \drawbox{2}{3}{-6}{blue!21} 

  \drawbox{3}{3}{-7}{blue!21} 
  \drawbox{4}{3}{-7}{blue!21} 
  \drawbox{5}{3}{-7}{blue!21} 
  \drawbox{6}{3}{-7}{blue!21}
  \drawbox{6}{3}{-6}{blue!21} 
  \drawbox{6}{3}{-5}{blue!21} 

  \drawbox{6}{3}{-4}{blue!21} 
  \drawbox{6}{3}{-3}{blue!21} 

  \drawbox{2}{2}{-7}{blue!21} 
  \drawbox{2}{2}{-6}{blue!21} 

  \drawbox{2}{2}{-5}{blue!21} 

  \drawbox{2}{3}{-4}{blue!21} 
  \drawbox{2}{3}{-5}{blue!21} 

  \drawbox{2}{2}{-4}{blue!21} 

  \drawbox{2}{2}{-5}{blue!21} 

  \drawbox{2}{3}{-4}{blue!21} 
  \drawbox{2}{2}{-4}{blue!21} 

  \drawbox{2}{2}{-1}{blue!21} 
  \drawbox{2}{2}{-3}{blue!21} 
  \drawbox{2}{2}{-2}{blue!21} 
  \drawbox{2}{2}{-1}{blue!21} 

  \drawbox{2}{2}{0}{blue!21} 
  \drawbox{2}{2}{1}{blue!21}

  \drawbox{3}{2}{1}{blue!21}
  \drawbox{4}{2}{1}{blue!21}
  \drawbox{5}{2}{1}{blue!21}
  \drawbox{6}{2}{1}{blue!21}        
  \drawbox{3}{2}{-3}{blue!21}
  \drawbox{4}{2}{-3}{blue!21}
  \drawbox{5}{2}{-3}{blue!21}
  \drawbox{6}{2}{-3}{blue!21} 

  \drawbox{3}{2}{-7}{blue!21} 
  \drawbox{4}{2}{-7}{blue!21} 
  \drawbox{5}{2}{-7}{blue!21} 
  \drawbox{6}{2}{-7}{blue!21}
  \drawbox{6}{2}{-6}{blue!21} 
  \drawbox{6}{2}{-5}{blue!21} 

  \drawbox{6}{2}{-4}{blue!21} 
  \drawbox{6}{2}{-3}{blue!21} 
\end{tikzpicture}
\end{document}

join=round improves the result, as suggested by Peter Grill.

6^3, perhaps?

  • 3
    Adding join=round should improve the picture. – Peter Grill Dec 7 '17 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.