tikz 制作的 3D 金字塔图

tikz 制作的 3D 金字塔图

如何用 tikz 绘制这个?

在此处输入图片描述

我需要画一幅但我不知道。

答案1

也许这可以让你开始:

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}[
    3d trapezium/.style={
        shape=trapezium,
        trapezium angle=60,
        trapezium stretches body=true,
        line width=0pt,
        inner xsep=0pt,
        fill=#1!75!black,
        text=white,
        font=\bfseries,
        text height=.8em,
        text depth=.2em,
        append after command={
            \pgfextra{ 
                \fill[#1!50!black] (\tikzlastnode.bottom left corner) --     
                    (\tikzlastnode.bottom right corner) -- 
                    ([shift={(-.1,-.275)}]\tikzlastnode.bottom right corner) -- 
                    ([shift={(.1,-.275)}]\tikzlastnode.bottom left corner) --
                    cycle;
            }
        }
    },
    3d triangle/.style={
        shape=isosceles triangle,
        isosceles triangle apex angle=60,
        line width=0pt,
        inner xsep=-2pt,
        shape border rotate=90,
        fill=#1!75!black,
        text=white,
        font=\bfseries,
        text height=.8em,
        text depth=.2em,
        append after command={
            \pgfextra{ 
                \fill[#1!50!black] (\tikzlastnode.left corner) --     
                    (\tikzlastnode.right corner) -- 
                    ([shift={(-.1,-.275)}]\tikzlastnode.right corner) -- 
                    ([shift={(.1,-.275)}]\tikzlastnode.left corner) --
                    cycle;
            }
        }
    },
    flag/.style={
        rectangle,
        anchor=west,
        yshift=-1ex,
        left color=#1!50!black,
        right color=transparent!0,
        opacity=.8,
        text opacity=1,
        align=left,
        text width=2.5cm,
        text height=.8em,
        text depth=.2em,
        inner xsep=1cm,
    }
]

\node[flag=red] at (0,0) (f-1) {Lecture};
\node[3d triangle=red] at (0,0) (a-1) {5\%};

\node[flag=orange] at ({1*cos(60)},{-1*sin(60)}) (f-2) {Reading};
\node[3d trapezium=orange, minimum width=2cm] at (0,{-1*sin(60)}) (a-2) {10\%};

\node[flag=yellow] at ({2*cos(60)},{-2*sin(60)}) (f-3) {Audio-visual};
\node[3d trapezium=yellow, minimum width=3cm] at (0,{-2*sin(60)}) (a-3) {20\%};

\node[flag=green] at ({3*cos(60)},{-3*sin(60)}) (f-4) {Demonstration};
\node[3d trapezium=green, minimum width=4cm] at (0,{-3*sin(60)}) (a-4) {30\%};

\node[flag=cyan] at ({4*cos(60)},{-4*sin(60)}) (f-5) {Discussion};
\node[3d trapezium=cyan, minimum width=5cm] at (0,{-4*sin(60)}) (a-5) {50\%};

\node[flag=blue] at ({5*cos(60)},{-5*sin(60)}) (f-6) {Practice doing};
\node[3d trapezium=blue, minimum width=6cm] at (0,{-5*sin(60)}) (a-6) {75\%};

\node[flag=violet] at ({6*cos(60)},{-6*sin(60)}) (f-7) {Teach others};
\node[3d trapezium=violet, minimum width=7cm] at (0,{-6*sin(60)}) (a-7) {90\%};

\end{tikzpicture}

\end{document}

在此处输入图片描述


编辑

最好3d trapezium也使用顶部三角形的样式,然后为其添加一个“三角形帽”。然后,根据设置的角度(我稍微增加了一点,使整体形状稍微窄一点)对齐三角形会更容易:

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}[
    3d trapezium angle/.code={
        \def\threedtrapeziumangle{#1}
    },
    3d trapezium angle=65,
    3d trapezium/.style={
        shape=trapezium,
        trapezium angle=\threedtrapeziumangle,
        trapezium stretches body=true,
        line width=0pt,
        inner xsep=0pt,
        fill=#1!75!black,
        text=white,
        font=\bfseries,
        text height=.8em,
        text depth=.2em,
        append after command={
            \pgfextra{ 
                \fill[#1!50!black] (\tikzlastnode.bottom left corner) --     
                    (\tikzlastnode.bottom right corner) -- 
                    ([shift={(-.1,-.33)}]\tikzlastnode.bottom right corner) -- 
                    ([shift={(.1,-.33)}]\tikzlastnode.bottom left corner) --
                    cycle;
            }
        }
    },
    triangle cap/.append style={
        append after command={
            \pgfextra{ 
                \path (\tikzlastnode.top left corner);
                \pgfgetlastxy{\temptopleftx}{\temptoplefty}
                \path (\tikzlastnode.top right corner);
                \pgfgetlastxy{\temptoprightx}{\temptoprighty}
                \fill[#1!75!black] (\tikzlastnode.top left corner) --     
                    (\tikzlastnode.top right corner) -- 
                    ([shift={(0,{tan(\threedtrapeziumangle)*0.5*(\temptoprightx-\temptopleftx)*1pt})}]\tikzlastnode.top side) --
                    cycle;
            }
        }
    },
    flag/.style={
        rectangle,
        anchor=west,
        yshift=-1ex,
        left color=#1!50!black,
        right color=transparent!0,
        opacity=.8,
        text opacity=1,
        align=left,
        text width=3.5cm,
        text height=.8em,
        text depth=.2em,
        execute at begin node=\hspace{1cm},
    },
]

    \node[flag=red] at (0,0) (f-1) {Lecture};
    \node[3d trapezium=red, triangle cap=red] at (0,0) (a-1) {5\%};
    
    \node[flag=orange] at ({1*cos(65)},{-1*sin(65)}) (f-2) {Reading};
    \node[3d trapezium=orange, minimum width={2cm*sin(65)}] at (0,{-1*sin(65)}) (a-2) {10\%};
    
    \node[flag=yellow] at ({2*cos(65)},{-2*sin(65)}) (f-3) {Audio-visual};
    \node[3d trapezium=yellow, minimum width={3cm*sin(65)}] at (0,{-2*sin(65)}) (a-3) {20\%};
    
    \node[flag=green] at ({3*cos(65)},{-3*sin(65)}) (f-4) {Demonstration};
    \node[3d trapezium=green, minimum width={4cm*sin(65)}] at (0,{-3*sin(65)}) (a-4) {30\%};
    
    \node[flag=cyan] at ({4*cos(65)},{-4*sin(65)}) (f-5) {Discussion};
    \node[3d trapezium=cyan, minimum width={5cm*sin(65)}] at (0,{-4*sin(65)}) (a-5) {50\%};
    
    \node[flag=blue] at ({5*cos(65)},{-5*sin(65)}) (f-6) {Practice doing};
    \node[3d trapezium=blue, minimum width={6cm*sin(65)}] at (0,{-5*sin(65)}) (a-6) {75\%};
    
    \node[flag=violet] at ({6*cos(65)},{-6*sin(65)}) (f-7) {Teach others};
    \node[3d trapezium=violet, minimum width={7cm*sin(65)}] at (0,{-6*sin(65)}) (a-7) {90\%};

\end{tikzpicture}

\end{document}

在此处输入图片描述

添加其他东西应该不会太复杂:

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}[
    3d trapezium angle/.code={
        \def\threedtrapeziumangle{#1}
    },
    3d trapezium angle=65,
    3d trapezium/.style={
        shape=trapezium,
        trapezium angle=\threedtrapeziumangle,
        trapezium stretches body=true,
        line width=0pt,
        inner xsep=0pt,
        fill=#1!75!black,
        text=white,
        font=\bfseries,
        text height=.8em,
        text depth=.2em,
        append after command={
            \pgfextra{ 
                \fill[#1!50!black] (\tikzlastnode.bottom left corner) --     
                    (\tikzlastnode.bottom right corner) -- 
                    ([shift={(-.1,-.33)}]\tikzlastnode.bottom right corner) -- 
                    ([shift={(.1,-.33)}]\tikzlastnode.bottom left corner) --
                    cycle;
            }
        }
    },
    triangle cap/.append style={
        append after command={
            \pgfextra{ 
                \path (\tikzlastnode.top left corner);
                \pgfgetlastxy{\temptopleftx}{\temptoplefty}
                \path (\tikzlastnode.top right corner);
                \pgfgetlastxy{\temptoprightx}{\temptoprighty}
                \fill[#1!75!black] (\tikzlastnode.top left corner) --     
                    (\tikzlastnode.top right corner) -- 
                    ([shift={(0,{tan(\threedtrapeziumangle)*0.5*(\temptoprightx-\temptopleftx)*1pt})}]\tikzlastnode.top side) --
                    cycle;
            }
        }
    },
    flag/.style={
        rectangle,
        anchor=west,
        yshift=-1ex,
        left color=#1!50!black,
        right color=transparent!0,
        opacity=.8,
        text opacity=1,
        align=left,
        text width=3.5cm,
        text height=.8em,
        text depth=.2em,
        execute at begin node=\hspace{1cm},
    },
]

    \node[flag=red] at (0,0) (f-1) {Lecture};
    \node[3d trapezium=red, triangle cap=red] at (0,0) (a-1) {5\%};
    
    \node[flag=orange] at ({1*cos(65)},{-1*sin(65)}) (f-2) {Reading};
    \node[3d trapezium=orange, minimum width={2cm*sin(65)}] at (0,{-1*sin(65)}) (a-2) {10\%};
    
    \node[flag=yellow] at ({2*cos(65)},{-2*sin(65)}) (f-3) {Audio-visual};
    \node[3d trapezium=yellow, minimum width={3cm*sin(65)}] at (0,{-2*sin(65)}) (a-3) {20\%};
    
    \node[flag=green] at ({3*cos(65)},{-3*sin(65)}) (f-4) {Demonstration};
    \node[3d trapezium=green, minimum width={4cm*sin(65)}] at (0,{-3*sin(65)}) (a-4) {30\%};
    
    \node[flag=cyan] at ({4*cos(65)},{-4*sin(65)}) (f-5) {Discussion};
    \node[3d trapezium=cyan, minimum width={5cm*sin(65)}] at (0,{-4*sin(65)}) (a-5) {50\%};
    
    \node[flag=blue] at ({5*cos(65)},{-5*sin(65)}) (f-6) {Practice doing};
    \node[3d trapezium=blue, minimum width={6cm*sin(65)}] at (0,{-5*sin(65)}) (a-6) {75\%};
    
    \node[flag=violet] at ({6*cos(65)},{-6*sin(65)}) (f-7) {Teach others};
    \node[3d trapezium=violet, minimum width={7cm*sin(65)}] at (0,{-6*sin(65)}) (a-7) {90\%};


    \node[anchor=east, text width=3.5cm, align=center, font=\itshape\footnotesize, color=white, rotate=270] at ([shift={(1,-.33)}]a-7.south) {Average retention rates};

    \node[anchor=west, bottom color=orange, top color=white, middle color=yellow, text width=5.25cm, font=\bfseries, rotate=90] at ([shift={(-1,-.33)}]a-7.south) {\textcolor{white}{Active} \hfill Passive};
    
    \draw[line width=.1cm, yellow!75!black] ([shift={(-1.5,-.33)}]a-7.south) |- (-4,0 |- a-1.north) node[above, anchor=south west, inner xsep=0pt, black] {Autitory};
    
    \draw[line width=.1cm, orange!75!black] ([shift={(-1.6,-.33)}]a-7.south) |- (-4,0 |- a-2.north) node[above, anchor=south west, inner xsep=0pt, black] {Visual};

    \draw[line width=.1cm, red!75!black] ([shift={(-1.7,-.33)}]a-7.south) |- (-4,0 |- a-5.north) node[above, anchor=south west, inner xsep=0pt, black] {Kinesthetic};

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容