我怎样才能使箭头位于节点的中心?

我怎样才能使箭头位于节点的中心?

我想将箭头的起点和终点与相应的节点置于中心

\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}

相关内容