
@Thorsten: You are right. I forgot to link to {TeX} SX; I only remembered to do it the other way around.
@Clemens: Thank you for the solution. It is very nice!
Consider the following MWE:
Code: Select all
\documentclass{article}
\usepackage[danish]{babel}
\usepackage{ifthenx}
\usepackage{verbatim}
\usepackage{tikz}
% Three counters
\newcounter{x}
\newcounter{y}
\newcounter{z}
% The angles of x,y,z-axes
\newcommand{\xaxis}{210}
\newcommand{\yaxis}{330}
\newcommand{\zaxis}{90}
% Color relativt to layer
\newcommand*{\cubecolors}[1]{%
\ifcase#1\relax
\or\colorlet{cubecolor}{green}%
\or\colorlet{cubecolor}{cyan}%
\or\colorlet{cubecolor}{yellow}%
\or\colorlet{cubecolor}{red}%
\or\colorlet{cubecolor}{purple}%
\or\colorlet{cubecolor}{blue}%
\else
\colorlet{cubecolor}{white}%
\fi
}
% The top side of a cube
\newcommand{\topside}[3]{%
\fill[fill=cubecolor,draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (0,1) --(150:1)--(0,0);
}
% The left side of a cube
\newcommand{\leftside}[3]{%
\fill[fill=cubecolor,draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
shift={(\zaxis:#3)}] (0,0) -- (0,-1) -- (210:1) --(150:1)--(0,0);
}
% The right side of a cube
\newcommand{\rightside}[3]{%
\fill[fill=cubecolor,draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (-30:1) --(0,-1)--(0,0);
}
% The cube
\newcommand{\cube}[3]{%
\topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
}
% Definition of \planepartition
\newcommand{\planepartition}[1]{
\setcounter{x}{-1}
\foreach \a in {#1} {
\addtocounter{x}{1}
\setcounter{y}{-1}
\foreach \b in \a {
\addtocounter{y}{1}
\setcounter{z}{-1}
\foreach \c in {0,...,\b} {
\addtocounter{z}{1}
\cubecolors{\c}
\ifthenelse{\c=0}{\setcounter{z}{-1},\addtocounter{y}{0}}{
\cube{\value{x}}{\value{y}}{\value{z}}}
}
}
}
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.6]
\planepartition{1}
\end{tikzpicture}
\hfill
\begin{tikzpicture}[scale=0.6]
\planepartition{{1,1,1},{1,2,1},{1,1,1}}
\end{tikzpicture}
\hfill
\begin{tikzpicture}[scale=0.6]
\planepartition{{1,1,1,1,1},{1,2,2,2,1},{1,2,3,2,1},{1,2,2,2,1},{1,1,1,1,1}}
\end{tikzpicture}
\end{figure}
\end{document}
I tried to change
Code: Select all
\foreach \c in {0,...,\b}
Code: Select all
\foreach \c in {\b,...,0}