在以下 MWE 中,矩阵中的节点未正确垂直对齐:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[sibling distance=6mm,level distance=1.3cm,every node/.style={inner sep=4pt, text depth=0pt, minimum width=24mm,minimum height=24mm,align=center,inner sep=2pt}]
\matrix [draw=red] {
\node[draw=black, rectangle] {A}; & \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] {B\\ C\\ D}; & \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] {Bbbbbbbb\\ Cccccccc\\ Dddddddd};\\
};
\end{tikzpicture}
\end{document}
这个问题似乎是由cylinder
因为第二个圆柱体的排列比第二个圆柱体更差。
顺便问一下,为什么cylinder
的方面取决于它包含的文本?
答案1
默认情况下,matrix nodes
它们与其对齐center
。TiKZ 提供了anchor
更改matrix cells
对齐方式的选项。如果要将所有节点与其底点对齐,请使用\matrix[anchor=south]
。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[every node/.style={inner sep=4pt,%
text depth=0pt, minimum width=24mm,%
minimum height=24mm, align=center, inner sep=2pt}]
\matrix [draw=red] {
\node[draw=black, rectangle] (a) {A}; &
\node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] (b) {B\\ C\\ D};
& \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] (c) {Bbbbbbbb\\
Cccccccc\\ Dddddddd};\\
};
\foreach \i in {a,b,c}
\fill[red] (\i.center) circle(1pt);
\draw[red] (a.center)--(b.center)--(c.center);
\begin{scope}[yshift=-5cm]
\matrix [draw=red,anchor=south] {
\node[draw=black, rectangle] (a) {A}; &
\node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] (b) {B\\ C\\ D};
& \node[draw=black,cylinder,shape border rotate=90,shape aspect=.25] (c) {Bbbbbbbb\\
Cccccccc\\ Dddddddd};\\
};
\foreach \i in {a,b,c}{
\fill[red] (\i.center) circle(1pt);
\fill[blue] (\i.south) circle(1pt);
}
\draw[red] (a.center)--(b.center)--(c.center);
\draw[blue] (a.south)--(b.south)--(c.south);
\end{scope}
\end{tikzpicture}
\end{document}