我使用了以下例子这里和这里绘制金字塔。我只需要 3 个部分,而且我处于连线位置,我知道如何制作一个间距相等的金字塔和一个颜色相同的金字塔,但不能同时制作两者。我希望顶部金字塔(形状)有颜色。此外,我想知道如何更改底部金字塔的形状,因为只需更改坐标就会导致 3 个重叠三角形。
\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections,backgrounds}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\begin{document}
\begin{figure}[htp]
\centering
\begin{tikzpicture}
\coordinate (A) at (-5,0) {};
\coordinate (B) at ( 5,0) {};
\coordinate (C) at (0,7) {};
\draw[name path=AC] (A) -- (C);
\draw[name path=BC] (B) -- (C);
\foreach \y/\A in {
0/bottom,
2/middle ,
4/hoch} {
\path[name path=horiz] (A|-0,\y) -- (B|-0,\y);
\draw[name intersections={of=AC and horiz,by=P},
name intersections={of=BC and horiz,by=Q}] (P) -- (Q)
node[midway,above,align=center,text width=
\dimexpr(6em-\y em)*5\relax] {\A};
}
\end{tikzpicture}
\begin{tikzpicture}[x=2.5cm,y=2cm]
\coordinate (A) at (-3,-1) {};
\coordinate (B) at (3,-1) {};
\coordinate (C) at (0,5) {};
\foreach \A/\col [count=\i] in {bottom/yellow,middle/blue,top/orange}
\draw[fill=\col] (C)--([shift={(-.5*\i,1*\i)}]B)--node[above,align=center] {\A}([shift={(.5*\i,1*\i)}]A)--cycle;
\end{tikzpicture}
\end{figure}
\end{document}
答案1
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\r{5} % Radius of your triangle
\foreach \i in {1,2,3} \coordinate (\i) at (90+120*\i:\r);
\draw[fill=orange] (1) -- (2) node[above,midway] {bottom} -- (3) -- cycle;
\path (1) -- (3) coordinate[pos=0.33] (a1) coordinate[pos=0.66] (a2);
\path (2) -- (3) coordinate[pos=0.33] (b1) coordinate[pos=0.66] (b2);
\foreach \i/\clr/\txt in {1/blue/middle,2/yellow/top} \draw[fill=\clr] (3) -- (b\i) -- (a\i) node[above,midway] {\txt} -- cycle;
\end{tikzpicture}
\end{document}