
Ich verwende den unten stehenden Code, der verschiedenfarbige Ebenen erstellt. Ich habe Probleme, eine Dekoration zu erhalten, die gleichzeitig für alle Ebenen in den drei Achsen funktioniert. Ich bitte um etwas Hilfe. Ich hoffe, 3 Farben a, b, c verwenden zu können, um eine Box an Position (a, b, c) mit Farbe a+b+c mod 3 einzufärben.
Code
% Plane partition
% Author: Jang Soo Kim
\documentclass{standalone}
\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}{-30}
\newcommand{\zaxis}{90}
% 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 cubecolors
\newcommand*\cubecolors[1]{%
\ifcase#1\relax
\or\colorlet{cubecolor}{green}%
\or\colorlet{cubecolor}{blue}%
\or\colorlet{cubecolor}{red}%
\or\colorlet{cubecolor}{green}%
\or\colorlet{cubecolor}{blue}%
\or\colorlet{cubecolor}{red}%
\else
\colorlet{cubecolor}{white}%
\fi
}
% 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{\a}
\ifthenelse{\c=0}{\setcounter{z}{-1},\addtocounter{y}{0}}{
\cube{\value{x}}{\value{y}}{\value{z}}}
}
}
}
}
\begin{document}
\begin{tikzpicture}
\planepartition{{5,3,2,2},{4,2,2,1},{3,2,1},{2,1},{1}}
\end{tikzpicture}
\end{document}
Antwort1
Ich denke, es muss eine Möglichkeit geben, die Farbgebung mithilfe von durchzuführen, mod
aber ich bin mir im Moment nicht sicher, wie (zu meiner Verteidigung: es ist schon etwas spät). In der Zwischenzeit kann ich Ihnen jedoch eine Alternative anbieten, mit der Sie die Zähler loswerden können, die zwar nützlich sind, aber dennoch zusätzlicher Code sind, sowie das ifthenx
Paket und den \ifthenelse
Befehl, die durch ersetzt werden \ifnum### ... \else ... \fi
.
Sie können Ihren \planepartition
Befehl also durch Folgendes ersetzen:
\newcommand\planepartition[1]{
\foreach \a [count=\x starting from -1] in {#1} {
\foreach \b [count=\y starting from -1] in \a {
\foreach \c [count=\z starting from -1] in {0,...,\b} {
\cubecolors{\a}
\ifnum\c=0
\else
\cube{\x}{\y}{\z}
\fi
}
}
}
}