答案1
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[pics/Lam/.style={code={
\draw (-0.45,0.1) -- (0,0.9) -- (0.45,0.1) (-0.45,0) -- (0.45,0);}}]
\path foreach \Y in {1,2,3}
{foreach \X in {1,...,\Y} {(\X-\Y/2,1-\Y) pic{Lam}}};
\end{tikzpicture}
\end{document}
这是 (更忠实于原始帖子) 的版本,底部没有线条,还有更多内容。你只需要说
\path pic{card house=3};
参见
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[pics/Lam/.style={code={
\def\pkv##1{\pgfkeysvalueof{/tikz/Lam/##1}}
\draw (-0.5*\pkv{shrink}*\pkv{width},0.1) --
(0,\pkv{shrink}*\pkv{height}) -- (0.5*\pkv{shrink}*\pkv{width},0.1)
\ifnum#1<\pkv{cutoff} (-0.5*\pkv{shrink}*\pkv{width},0) -- (0.5*\pkv{shrink}*\pkv{width},0)
\fi;}},
pics/card house/.style={code={
\tikzset{Lam/cutoff=#1}
\path foreach \Y in {1,...,#1}
{foreach \X in {1,...,\Y}
{(\X*\pgfkeysvalueof{/tikz/Lam/width}-\Y*\pgfkeysvalueof{/tikz/Lam/width}/2,
-\Y*\pgfkeysvalueof{/tikz/Lam/height}) pic{Lam=\Y}}};
}},
/tikz/Lam/.cd,cutoff/.initial=3,width/.initial=1,height/.initial=1,shrink/.initial=0.9,
]
\path pic{card house=3} (4,0) pic[red]{card house=4} (9,0) pic[blue,thick]{card house=5};
\end{tikzpicture}
\end{document}
这有什么用呢?噢,当然了!
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikzlings}
\newif\iftikzling
\begin{document}
\begin{tikzpicture}[pics/Lam/.style={code={
\def\pkv##1{\pgfkeysvalueof{/tikz/Lam/##1}}
\draw (-0.5*\pkv{shrink}*\pkv{width},0.1) --
(0,\pkv{shrink}*\pkv{height}) -- (0.5*\pkv{shrink}*\pkv{width},0.1)
\ifnum#1<\pkv{cutoff} (-0.5*\pkv{shrink}*\pkv{width},0) -- (0.5*\pkv{shrink}*\pkv{width},0)
\fi;
\iftikzling
\tikzling[scale=0.25*\pkv{height}*\pkv{shrink}]
\fi}},
pics/card house/.style={code={
\tikzset{Lam/cutoff=#1}
\path foreach \Y in {1,...,#1}
{foreach \X in {1,...,\Y}
{(\X*\pgfkeysvalueof{/tikz/Lam/width}-\Y*\pgfkeysvalueof{/tikz/Lam/width}/2,
-\Y*\pgfkeysvalueof{/tikz/Lam/height}) pic{Lam=\Y}}};
}},
/tikz/Lam/.cd,cutoff/.initial=3,width/.initial=1,height/.initial=1,shrink/.initial=0.9,
tikzling/.is if=tikzling
]
\path[/tikz/Lam/.cd,height=3,width=3,tikzling=true] pic[blue,thick]{card house=5};
\end{tikzpicture}
\end{document}