看完之后这因此,我尝试了下面的例子,但是分支之间的距离现在是逐个中心计算的。我该如何改进它,让 3 个分支逐个边界均匀分布?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}
\tikzset{
node distance=0 and 2cm,
start chain=going right,
box/.style={on chain,draw,outer sep=0,inner sep=2pt},
hide/.style={on chain,draw=none,inner sep=0},
}
\node[hide] {};
\begin{scope}[start branch=B1 going below]
\foreach \x in {A,B,C,D} {
\node[box,text width=2cm] (\x) {\x};
}
\end{scope}
\node[hide] {};
\begin{scope}[start branch=B2 going below]
\foreach \x in {E,F,G,H,I,J,K} {
\node[box,text width=1cm] (\x) {\x};
}
\end{scope}
\node[hide] {};
\begin{scope}[start branch=B3 going below]
\foreach \x in {L,M,N} {
\node[box,text width=1cm] (\x) {\x};
}
\end{scope}
\end{tikzpicture}
\end{document}
输出:
答案1
您不需要任何hide
节点或其他技巧,只需要一个matrix
,就可以通过调整距离column sep
。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}
\tikzset{
node distance=0 and 2cm,
box/.style={on chain,draw,outer sep=0,inner sep=2pt},
}
\matrix[column sep=3em]{
\begin{scope}[start chain=going below]
\foreach \x in {A,B,C,D} {
\node[box,text width=2cm] (\x) {\x};
}
\end{scope}
&
\begin{scope}[start chain=going below]
\foreach \x in {E,F,G,H,I,J,K} {
\node[box,text width=1cm] (\x) {\x};
}
\end{scope}
&
\begin{scope}[start chain=going below]
\foreach \x in {L,M,N} {
\node[box,text width=1cm] (\x) {\x};
}
\end{scope}
\\
};
\end{tikzpicture}
\end{document}