2

From the answer to this question, is it possible to make a lower cube position void, to create this drawing

\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}% to suppresses (hide) navigation symbols bar
\usepackage{tikz}
\usepackage{verbatim}
% 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=yellow, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}, opacity=.7] (0,0) -- (30:1) -- (0,1) --(150:1)--(0,0);
}
% The left side of a cube
\newcommand\leftside[3]{
  \fill[fill=green, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}, opacity=.7] (0,0) -- (0,-1) -- (210:1) --(150:1)--(0,0);
}
% The right side of a cube
\newcommand\rightside[3]{
  \fill[fill=blue, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}, opacity=.7] (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}
}
\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}
 \ifnum \b>0
  \foreach \c in {1,...,\b} {
   \addtocounter{z}{1}
   \cube{\value{x}}{\value{y}}{\value{z}}
}\fi}}}
\begin{document} 
\begin{tikzpicture}
\planepartition{{2,1,2,1,2,1,2},{1,0,0,0,0,0,1},{1,0,0,0,0,0,1},{1,0,0,0,0,0,1},{2,1,2,1,2,1,2}}%1st column from back to front{row1,... from left to right}%0 is the same as 2% it does not allow void for 0
\end{tikzpicture}
\end{document} 

enter image description here

2 Answers 2

2

In this case, it is sufficient to build layer by layer (floor by floor) from the lowest to the highest.

To do this, I modified the loop by adding an optional argument that is set to 0 by default. This allows you to keep the old syntax for previous graphics.

This optional argument is simply added to the z counter in the loop:

\addtocounter{z}{#1}

By default, this argument is 0 and builds the partition like the old code, i.e. on the ground floor.

  • When this argument is equal to 1, it builds a partition one floor above.
  • when it is equal to 2, it builds two floors above, etc.

It is always possible to build several layers (or floors) at the same time as in the old code.

\newcommand\planepartition[2][0]{
 \setcounter{x}{-1}
  \foreach \a in {#2} {
        \addtocounter{x}{1}
        \setcounter{y}{-1}
            \foreach \b in \a {
            \addtocounter{y}{1}
            \setcounter{z}{-1}
            \addtocounter{z}{#1} %partition of the desired floor (layer)
            \ifnum \b>0
            \foreach \c in {1,...,\b} {
                \addtocounter{z}{1}
                \cube{\value{x}}{\value{y}}{\value{z}}
      }\fi
    }
  }
}

cubes

\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}% to suppresses (hide) navigation symbols bar
\usepackage{tikz}
\usepackage{verbatim}
% 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=yellow,fill opacity=.7, 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=green,fill opacity=.7, 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=blue,fill opacity=.7, 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
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
%  a b c
%  d e
\newcommand\planepartition[2][0]{
 \setcounter{x}{-1}
  \foreach \a in {#2} {
        \addtocounter{x}{1}
        \setcounter{y}{-1}
            \foreach \b in \a {
            \addtocounter{y}{1}
            \setcounter{z}{-1}
            \addtocounter{z}{#1} %partition of the desired floor (layer)
            \ifnum \b>0
            \foreach \c in {1,...,\b} {
                \addtocounter{z}{1}
                \cube{\value{x}}{\value{y}}{\value{z}}
      }\fi
    }
  }
}
\begin{document} 


\begin{tikzpicture}% Old syntax is functional
\planepartition{{2,1,2,1,2,1,2},{1,0,0,0,0,0,1},{1,0,0,0,0,0,1},{1,0,0,0,0,0,1},{2,1,2,1,2,1,2}}
\end{tikzpicture}
\begin{tikzpicture}% The optional argument allow to build layer by layer
\planepartition{{1,1,0,1,0,1,1},{1,0,0,0,0,0,1},{1,0,0,0,0,0,1},{1,0,0,0,0,0,1},{1,1,0,1,0,1,1}}
\planepartition[1]{{1,0,1,0,1,0,1},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{1,0,1,0,1,0,1}}
\end{tikzpicture}
\end{document} 
2
  • Thank you very much for your answer. Both your code and marmot`s work fine.
    – Hany
    Commented Jan 20, 2019 at 7:39
  • 1
    Thank you, my way of doing things allows you to place several holes on the same column.
    – AndréC
    Commented Jan 20, 2019 at 7:40
2

Yes. I added an optional parameter which indicates how many boxes are to be skipped. So 2/1 means two boxes but skip the first one.

\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}% to suppresses (hide) navigation symbols bar
\usepackage{tikz}
\usepackage{verbatim}
% 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=yellow, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}, opacity=.7] (0,0) -- (30:1) -- (0,1) --(150:1)--(0,0);
}
% The left side of a cube
\newcommand\leftside[3]{
  \fill[fill=green, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}, opacity=.7] (0,0) -- (0,-1) -- (210:1) --(150:1)--(0,0);
}
% The right side of a cube
\newcommand\rightside[3]{
  \fill[fill=blue, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}, opacity=.7] (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}
}
\newcommand\planepartition[1]{
 \setcounter{x}{-1}
  \foreach \a in {#1} {
\addtocounter{x}{1}
\setcounter{y}{-1}
\foreach \b/\d in \a {
  \addtocounter{y}{1}
  \setcounter{z}{-1}
 \ifnum\b>0
  \ifnum\b=\d
   \foreach \c in {1,...,\b} {
    \addtocounter{z}{1}
    \cube{\value{x}}{\value{y}}{\value{z}}}
   \else
   \pgfmathtruncatemacro{\cmin}{1+\d}
   \addtocounter{z}{\d}
   \foreach \c in {\cmin,...,\b} {
    \addtocounter{z}{1}
    \cube{\value{x}}{\value{y}}{\value{z}}}
   \fi
  \fi}}}
\begin{document} 
\begin{tikzpicture}
\planepartition{{2,1,2/1,1,2/1,1,2},{1,0,0,0,0,0,1},{1,0,0,0,0,0,1},{1,0,0,0,0,0,1},{2,1,2/1,1,2/1,1,2}}%1st column from back to front{row1,... from left to right}%0 is the same as 2% it does not allow void for 0
\end{tikzpicture}
\end{document} 

enter image description here

5
  • Let me mention that in the above the old syntax is, of course, still functional. So if you drop the /1 you will get the original result. But with this method you do not have to draw two partitions.
    – user121799
    Commented Jan 20, 2019 at 7:06
  • Which /1 are you referring to?
    – Hany
    Commented Jan 20, 2019 at 7:10
  • I tried your suggestion, but unfortunately it did not work. Would you please give me the whole code.
    – Hany
    Commented Jan 20, 2019 at 7:25
  • I am sorry your answer was not displayed when I posted my comment. I followed your answer and it works fine. Thank you.
    – Hany
    Commented Jan 20, 2019 at 7:28
  • Thank you very much. Both your answer and AndréC`s work fine. I am confused about which answer to mark!!!
    – Hany
    Commented Jan 20, 2019 at 7:43

You must log in to answer this question.

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