![我怎样才能使箭头位于节点的中心?](https://linux22.com/image/430890/%E6%88%91%E6%80%8E%E6%A0%B7%E6%89%8D%E8%83%BD%E4%BD%BF%E7%AE%AD%E5%A4%B4%E4%BD%8D%E4%BA%8E%E8%8A%82%E7%82%B9%E7%9A%84%E4%B8%AD%E5%BF%83%EF%BC%9F.png)
我想将箭头的起点和终点与相应的节点置于中心
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary {backgrounds,fit,positioning,shapes}
\begin{document}
\begin{tikzpicture}[
every node/.style={on grid},
every fit/.style={draw,,ellipse,text width=25pt},
>=latex
]
\node[ellipse, label=$1$] (1) {};
\node[ellipse, below = of 1, label=$2$] (2) {};
\node[ellipse, below = of 2, label=$3$] (3) {};
\node[ellipse, below = of 3, label=$4$] (4) {};
\node[above=of 1,anchor=south] {$A$};
\node[ellipse, label=$x$, right = 3cm of 1] (x) {};
\node[ellipse, below = of x, label=$y$] (y) {};
\node[ellipse, below = of y, label=$z$] (z) {};
\node[above=of x,anchor=south] {$B$};
\draw[->] (1) -- (y);
\draw[->] (1) -- (z);
\draw[->] (3) -- (y);
\draw[->] (4) -- (x);
\draw[->] (4) -- (z);
\begin{pgfonlayer}{background}
\node[fit= (1) (4) ] {};
\node[fit= (x) (z) ] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
现在看起来是这样
答案1
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary {backgrounds,fit,positioning,shapes}
\begin{document}
\begin{tikzpicture}[
every node/.style={on grid},
every fit/.style={draw,,ellipse,text width=25pt},
>=latex
]
\node[ ] (1) {$1$};
\node[below=of 1, ] (2) {$2$};
\node[below=of 2, ] (3) {$3$};
\node[below=of 3, ] (4) {$4$};
% \node[above=of 1,anchor=south] {$A$};
\node[right=3cm of 1] (x) {$x$};
\node[below=of x, ] (y) {$y$};
\node[below=of y,] (z) {$z$};
% \node[above=of x,anchor=south] {$B$};
\draw[->] (1) -- (y);
\draw[->] (1) -- (z);
\draw[->] (3) -- (y);
\draw[->] (4) -- (x);
\draw[->] (4) -- (z);
\begin{pgfonlayer}{background}
\node[fit=(1)(4), label=90:$A$] {};
\node[fit=(x)(z), label=90:$B$] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}