另一个关于使用矩阵对齐节点的问题tikz
。考虑以下内容:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column sep=5mm,row sep=3mm, align=center,
nodes={rectangle,draw, text width = 2cm} ]{
& \node{row1-2}; & \\
\node{row2-1}; & & \node{row2-3 long in two rows};\\
};
\draw[->] (m-1-2) |- (m-2-1);
\draw[->] (m-1-2) |- (m-2-3);
\end{tikzpicture}
\end{document}
这让我得到这样的结果:
第二排的箱子怎样才能正确对齐?
答案1
搞清楚了。只需添加anchor=center
到节点定义,就可以了:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m)[
matrix of nodes, column sep=5mm, row sep=3mm, align=center,
nodes={rectangle, draw, text width=2cm, anchor=center}
]{
& \node{row1-2}; & \\
\node{row2-1}; & & \node{row2-3 long in two rows}; \\
};
\draw[->] (m-1-2) |- (m-2-1);
\draw[->] (m-1-2) |- (m-2-3);
\end{tikzpicture}
\end{document}