使用 tikz 定位相对于底边的节点

使用 tikz 定位相对于底边的节点

我想使用 TikZ 图片创建一组步骤。我尝试使用该positioning库将步骤彼此相邻放置,如下所示:

在此处输入图片描述

(不用于比例,底部边缘应对齐)

所以我这样做了:

\begin{tikzpicture}
  \node[draw, rectangle,             align=center, minimum height=2cm] (1) {\textbf{1} \\ Step};
  \node[draw, rectangle, right=of 1, align=center, minimum height=3cm] (2) {\textbf{2} \\ Step};
  \node[draw, rectangle, right=of 2, align=center, minimum height=4cm] (3) {\textbf{3} \\ Step};
  \node[draw, rectangle, right=of 3, align=center, minimum height=5cm] (4) {\textbf{4} \\ Step};
  \node[draw, rectangle, right=of 4, align=center, minimum height=6cm] (5) {\textbf{5} \\ Step};
\end{tikzpicture}

但它看起来对齐的是节点中心,而不是底部边缘:

在此处输入图片描述

这根本不像步骤。我该怎么做(不用at手动定位每个节点)?

答案1

在此处输入图片描述

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
   box/.style = {rectangle, draw, minimum width=1cm,
                 minimum height=#1, align=center},
node distance = 0mm and 5mm
                    ]
\node[box=2cm] (1) {\textbf{1} \\ Step};
\node[box=3cm, above right=of 1.south east] (2) {\textbf{2} \\ Step};
\node[box=4cm, above right=of 2.south east] (3) {\textbf{3} \\ Step};
\node[box=5cm, above right=of 3.south east] (4) {\textbf{4} \\ Step};
\node[box=6cm, above right=of 4.south east] (5) {\textbf{5} \\ Step};
\end{tikzpicture}
\end{document}

附录: 可能,稍微短一点的代码(四年后......):

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
   box/.style = {rectangle, draw, minimum width=1cm,
                 minimum height=#1, align=center, anchor=south west},
node distance = 0mm and 5mm
                    ]
\node[box=2cm]                        (1) {\textbf{1} \\ Step};
\node[right=of 1.south east, box=3cm] (2) {\textbf{2} \\ Step};
\node[right=of 2.south east, box=4cm] (3) {\textbf{3} \\ Step};
\node[right=of 3.south east, box=5cm] (4) {\textbf{4} \\ Step};
\node[right=of 4.south east, box=6cm] (5) {\textbf{5} \\ Step};
\end{tikzpicture}
\end{document}

结果和以前一样。

相关内容