6

I am using

\begin{document}
\begin{tikzpicture}
\foreach \x in{0,...,4}
{   \draw (0,\x ,4) -- (4,\x ,4);
    \draw (\x ,0,4) -- (\x ,4,4);
    \draw (4,\x ,4) -- (4,\x ,0);
    \draw (\x ,4,4) -- (\x ,4,0);
    \draw (4,0,\x ) -- (4,4,\x );
    \draw (0,4,\x ) -- (4,4,\x );
}
\end{tikzpicture}

\end{document}

enter image description here

to create cubes. However I would like to numerate the cells inside the cube. Any idea how I could do it?

enter image description here

3

1 Answer 1

5

With a simple foreach-loop. The only tricky thing is to define the vertical cells in reversed order (2-\y) so that maths can do its magic to number the cells.

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\foreach \x in{0,...,4}
{   \draw (0,\x ,4) -- (4,\x ,4); %horizontal front
    \draw (\x ,0,4) -- (\x ,4,4); %vertical front
    \draw (4,\x ,4) -- (4,\x ,0);
    \draw (\x ,4,4) -- (\x ,4,0);
    \draw (4,0,\x ) -- (4,4,\x );
    \draw (0,4,\x ) -- (4,4,\x );
}

\foreach \x in{0,...,3}{    
    \foreach \y in{0,...,3}{
        \node[] at (\x-1,2-\y) {\pgfmathprint{int(\x+4*\y)}};
    }
}
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .