TikZ でノードが正しく接続されていない

TikZ でノードが正しく接続されていない

私は次のことを達成したいと考えています。

ここに画像の説明を入力してください

しかし、ノードの接続が正しく機能していません。次の出力が表示されます。

ここに画像の説明を入力してください

これを修正するにはどうすればいいですか、どこが間違っているのでしょうか。

MWE:

\documentclass[tikz]{article}
\usepackage{tikz}
\tikzset{square/.style = {
    shape  = rectangle,
    fill   = gray!50,
    draw   = black,
    thick
}}

\tikzset{circle/.style = {
    shape  = circle,
    fill   = blue!20,
    draw   = blue,
    thick
}}

\begin{document}
\begin{tikzpicture}
  \draw[square] (-4,4)rectangle node (r1) {r1} (-3,5);
  \draw[circle] (-1,4.5) circle [radius=0.5cm] node (s1) {s1};
  \draw[->] (r1.west) -- (s1.east);

\end{tikzpicture}
\end{document} 

私は、\draw[->] (r1.west) -- (s1.east);

答え1

正しい写真

\documentclass[tikz,margin=3mm]{standalone}
\tikzset{squarenode/.style = {
    shape  = rectangle,
    fill   = gray!50,
    draw   = black,
    thick,
    minimum size=1cm %%%% Take note of this!
},
    circlenode/.style = {
    shape  = circle,
    fill   = blue!20,
    draw   = blue,
    thick,
    minimum size=1cm %%%% and this!
}}

\begin{document}
\begin{tikzpicture}
  \draw (-4,4.5) node[squarenode] (r1) {r1}; % Or \node[squarenode] (r1) at (-4,4.5) {r1};
  \draw (-1,4.5) node[circlenode] (s1) {s1}; % Or \node[circlenode] (s1) at (-1,4.5) {s1};
  \draw[->] (r1) -- (s1); % or (r1.east)--(s1.west);

\end{tikzpicture}
\end{document} 

ここに画像の説明を入力してください

いくつかの注意事項(重要!)

  1. circleは定義済みのオプションなので、新しい を定義してはなりませんcircle。これを に変更しましたcirclenode
  2. 円と四角形を手動で描く必要はありません。 ノードと の形状を使用できますminimum size。 さらに制御するには、minimum heightと を使用しますminimum width
  3. sを多用することはお勧めしません\tikzset{}
  4. tikzは のオプションではありませんarticle。 は のオプションですstandalonetikzオプションをすでにロードしている場合は、 は必要ありません\usepackage{tikz}

(r1)--(s1)と使用時の違い(r1.east)--(s1.west)

\documentclass[tikz,margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[draw] (a) at (0,0) {Some text};
\node[draw] (b) at (5,3) {Hello world};
\draw[thick] (0,0)--(5,3);
\draw[red] (a)--(b);
\draw[blue] (a.east)--(b.west);
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

赤い線と青い線の始点と終点をよく見てください。

関連情報