\documentclass{article}
\usepackage{tikz}
\usepackage{ctex}
\begin{document}
\usetikzlibrary{shapes.geometric,arrows,positioning}
\flushleft
\begin{tikzpicture}[level1/.style={regular polygon, regular polygon sides=3,fill=orange,draw=black, minimum width=3cm, minimum height=2cm},level2/.style={rectangle, rounded corners, fill=purple, minimum width=3cm, minimum height=2cm},level3/.style={trapezium,trapezium angle=70,fill=blue,draw=black,minimum height=1.3cm}]
\tikzset{trapezium stretches=true}
\node(a1)[level1]{雅思一对一精品教程(推荐)};
\node(b1)[level2,below=1cm of a1,xshift=-5cm]{雅思口语提升班};
\node(b2)[level2,right=of b1]{雅思听力提升班};
\node(b3)[level2,right=of b2]{雅思阅读提升班};
\node(b4)[level2, right=of b3]{雅思写作提升班};
\node(c1)[level3,below=of b1]{夯实基础:雅思语法讲解};
\node(c2)[level3,right = of c1]{夯实基础:雅思发音讲解};
\node(c3)[level3,right= of c2]{夯实基础: 雅思词汇讲解};
\end{tikzpicture}
\end{document}
如您所见,图片很丑而且不对称。我正在寻找某种方法使其更对称。我想我可以计算出我需要的 xshift,但这不是我想要的。有没有更简单的方法可以让 tikz 自动对齐节点?
答案1
首先,请允许我为无法使用您的角色表示歉意。但是,问题的答案是:可以,例如使用matrix of nodes
。顺便说一句,您可以设置node distance
,然后您就不必再说 了below=1cm
。
\documentclass[tikz,border=3mm]{standalone}
% please put the libraries in the preamble
\usetikzlibrary{shapes.geometric,positioning,matrix}
\begin{document}
\begin{tikzpicture}[level1/.style={regular polygon, regular polygon sides=3,
fill=orange,draw=black, minimum width=3cm, minimum height=2cm},
level2/.style={rectangle, rounded corners, fill=purple, minimum width=3cm,
minimum height=2cm},level3/.style={trapezium,trapezium angle=70,fill=blue,
draw=black,minimum height=1.3cm},node distance=1cm]
\tikzset{trapezium stretches=true}
\node(a1)[level1]{AAAAAAAAA(AA)};
\node[matrix of nodes,below=of a1,inner sep=0pt,nodes={level2,anchor=center},column sep=1cm] (b)
{AAAAAAA & AAAAAAA & AAAAAAA & AAAAAAA \\};
\node[matrix of nodes,below=of b,inner sep=0pt,nodes={level3,anchor=center},column sep=1cm] (c)
{AAAA:AAAAAA & AAAA: AAAAAA & AAAA: AAAAAA\\};
\end{tikzpicture}
\end{document}