从答案到这个问题,是否可以将下方的立方体位置设为空,以创建此绘图
\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}
答案1
在这种情况下,逐层构建就足够了(逐层)从最低到最高。
为此,我修改了循环,添加了一个0
默认设置为的可选参数。这样您就可以保留以前图形的旧语法。
这个可选参数只是添加到z
循环中的计数器:
\addtocounter{z}{#1}
默认情况下,此参数是0
和旧代码一样构建分区,即在底层。
- 当此参数等于时
1
,它会在上一层构建一个分区。 - 当它等于时
2
,它会在上面建造两层,等等。
总是可以构建多个层(或楼层)与旧代码同时。
\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
}
}
}
\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
是的。我添加了一个可选参数,表示要跳过多少个框。这2/1
意味着两个框,但跳过第一个。
\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}