![除了 xshift 和 yshift 之外,如何将 tikz 矩阵定位到特定点](https://linux22.com/image/342902/%E9%99%A4%E4%BA%86%20xshift%20%E5%92%8C%20yshift%20%E4%B9%8B%E5%A4%96%EF%BC%8C%E5%A6%82%E4%BD%95%E5%B0%86%20tikz%20%E7%9F%A9%E9%98%B5%E5%AE%9A%E4%BD%8D%E5%88%B0%E7%89%B9%E5%AE%9A%E7%82%B9.png)
我习惯使用\node[right=of SOME_OTHER_NODE]
和,\node[...] at (SOME_COORDINATE)
但这些功能似乎在中不可用\matrix
,我能想到的就是使用xshift
和yshift
。还有其他方法吗?例如,我想jetsam
在 处定位下面的矩阵,(jetsam_link |- flotsam.north west)
但不知道该怎么做。
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, calc}
\begin{document}
\begin{tikzpicture}[
>=latex,
scale=1.2,
open circle/.style={
circle, inner sep=0pt,
thick,draw=black,
fill = white,
},
junction/.style={open circle, minimum size=0.5mm,fill=black, node distance=5mm},
table/.style={
matrix of nodes,
nodes={draw=black, font={\ttfamily}, align=left, anchor=center,
text height=1.5ex, text depth=0.5ex, inner sep=1mm},
column sep=0,row sep=0, inner sep=0,
anchor=north west
},
kvmap/.style={
table,
column 1/.style={text width=2cm},
column 2/.style={text width=1.5cm},
},
list/.style={
table,
column 1/.style={text width=2cm},
}
]
\matrix (root) [kvmap, nodes={fill=white!70!yellow}]
{
foo & 37 \\
bar & {} \\
baz & "hey" \\
quux & {} \\
flotsam & {} \\
jetsam & {} \\
};
\matrix (bar) [kvmap, nodes={fill=white!70!yellow},
xshift=5cm, yshift=2cm,
]{
name & "Jason" \\
color & "yellow" \\
};
\matrix (quux) [kvmap, nodes={fill=white!70!yellow},
xshift=5cm, yshift=0.5cm,
]{
fears & {} \\
};
\matrix (fears) [list, nodes={fill=white!70!yellow},
xshift=10cm, yshift=0.5cm,
]{
"clowns" \\
"fire" \\
"poverty" \\
};
\matrix (flotsam) [kvmap, nodes={fill=white!70!yellow},
xshift=5cm, yshift=-1.3cm,
column 2/.style={text width=3cm},
]{
origin & "New York" \\
destination & "San Francisco" \\
};
\matrix (jetsam) [list, nodes={fill=white!70!yellow},
xshift=5cm, yshift=-2.59cm,
]{
1 \\
2 \\
3 \\
};
\node[junction](root_link) at ($(root-1-1.north west) + (-5mm,10mm)$){};
\node[junction](bar_link) at (root-2-2){};
\node[junction](quux_link) at (root-4-2){};
\node[junction](flotsam_link) at (root-5-2){};
\node[junction](jetsam_link) at (root-6-2){};
\node[junction](fears_link) at (quux-1-2){};
\draw[thick, ->] (root_link) |- (root-1-1.west);
\draw[thick, ->] (bar_link) -- (bar_link -| root.east) -- ++(2mm,0) |- (bar-1-1.west);
\draw[thick, ->] (quux_link) -- (quux_link -| root.east) -- ++(4mm,0) |- (quux-1-1.west);
\draw[thick, ->] (fears_link) -- (fears-1-1.west);
\draw[thick, ->] (flotsam_link) -- (flotsam_link -| root.east) -- ++(6mm,0) |- (flotsam-1-1.west);
\draw[thick, ->] (jetsam_link) -- (jetsam_link -| root.east) -- ++(6mm,0) |- (jetsam-1-1.west);
\end{tikzpicture}
\end{document}
答案1
哦,没关系,不知怎的,我的语法不正确;这个有效。
\matrix (jetsam) [list, nodes={fill=white!70!yellow},
] at (root-6-1.north -| flotsam.north west) {
1 \\
2 \\
3 \\
};