如何在节点的中心画一条线?

如何在节点的中心画一条线?

正如标题所写,我需要让线条进入圆心。 [代码部分位于:%Pfeile von den Dots zu den K-Kreisen] 我不想使用坐标,只想使用相互参考的节点。

    \documentclass{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
    [thick,node distance = 12ex, 
    box/.style={fill=white,rectangle, draw=black}, 
    blackdot/.style={inner sep = 0, minimum size=3pt,shape=circle,fill,draw=black},
    plus/.style={fill=white,circle,inner sep = 0,thick,draw},
    metabox/.style={inner sep = 3ex,rectangle,draw,dotted,fill=gray!20!white}
    circle/.style={fill=white, circle, draw=black}
    ]

\node(Sum1) [box, minimum size = 6ex]{$\sum_{1}^{}$};
\node(Sum2) [box, minimum size = 6ex, below of = Sum1, yshift = 2 ex]{$\sum_{2}^{}$};

\node(k1) [plus, left of = Sum1, minimum size = 6 ex]{$k_1$};
\node(k2) [plus, right of = Sum2, minimum size = 6 ex]{$k_2$};

\node(dot1) [blackdot, right of = Sum1, xshift = -4ex]{};
\node(dot2) [blackdot, left of = Sum2, xshift = 4ex]{};

%Pfeile von den Dots zu den K-Kreisen
\node(Hilfspunkt2) [draw=none, fill=none, below of = dot2, yshift=4ex]{};
\draw [-] (dot2) -- (Hilfspunkt2){};
\draw [->] (Hilfspunkt2) -| (k2){};
\node(Hilfspunkt1) [minimum size = 0.1mm, above of = dot1, yshift=-4ex]{};
\draw [-] (dot1) -- (Hilfspunkt1){};
\draw [->] (Hilfspunkt1) -| (k1){};

%Pfeile zu den k-Kreisen
\node(out1)   [right of = k2, minimum size=0pt, inner sep = 0pt, xshift = -3ex]{};
\node(out2)   [left of = k1, minimum size=0pt, inner sep = 0pt, xshift = 3ex]{};
\draw[->](out1) -- (k2) node[below, xshift = 6 ex]{$v_2$};
\draw[->](out2) -- (k1)node[below, xshift = -6 ex]{$v_1$};

%Verbindung zwischen Sum-Boxen und den Nodepunkten
\draw[-](Sum1) -- (dot1){};
\draw[-](Sum2) -- (dot2){};

%Pfeile von den K-Kreisen zu den Sum-Boxen
\draw[->](k1) -- (Sum1)node[below, xshift=-6ex]{$u_1$};
\draw[->](k2) -- (Sum2)node[below, xshift=6ex]{$u_2$};

%Eckpfeile von den Nodepunkten zu den k-Kreisen
\draw[->] (dot1) -| (k2) node[xshift=-4ex, yshift=8ex]{$y_1$};
\draw[->] (dot2) -| (k1) node[xshift=4ex, yshift=-8ex]{$y_2$};

    \end{tikzpicture}
\end{document}

答案1

您可以使用center节点的锚点。您还可以通过加载positioning库来简化代码。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}
    [thick,node distance = 12ex, 
    box/.style={fill=white,rectangle, draw=black}, 
    blackdot/.style={inner sep = 0, minimum size=3pt,shape=circle,fill,draw=black},
    plus/.style={fill=white,circle,inner sep = 0,thick,draw},
    metabox/.style={inner sep = 3ex,rectangle,draw,dotted,fill=gray!20!white}
    circle/.style={fill=white, circle, draw=black}
    ]

\node(Sum1) [box, minimum size = 6ex]{$\sum_{1}^{}$};
\node(Sum2) [box, minimum size = 6ex, below of = Sum1, yshift = 2 ex]{$\sum_{2}^{}$};

\node(k1) [plus, left of = Sum1, minimum size = 6 ex]{$k_1$};
\node(k2) [plus, right of = Sum2, minimum size = 6 ex]{$k_2$};

\node(dot1) [blackdot, right of = Sum1, xshift = -4ex,label=below:$y_1$]{};
\node(dot2) [blackdot, left of = Sum2, xshift = 4ex,label=above:$y_2$]{};

%Pfeile von den Dots zu den K-Kreisen
\node(Hilfspunkt2) [draw=none, fill=none,below=3em of dot2]{};
\draw [->] (dot2) -- (Hilfspunkt2.center) -| (k2);
\node(Hilfspunkt1) [minimum size = 0.1mm, above=3em of dot1]{};
\draw [->] (dot1) -- (Hilfspunkt1.center) -| (k1);

%Pfeile zu den k-Kreisen
\node(out1)   [right of = k2, minimum size=0pt, inner sep = 0pt, xshift = -3ex]{};
\node(out2)   [left of = k1, minimum size=0pt, inner sep = 0pt, xshift = 3ex]{};
\draw[->](out1) -- (k2) node[below, xshift = 6 ex]{$v_2$};
\draw[->](out2) -- (k1)node[below, xshift = -6 ex]{$v_1$};

%Verbindung zwischen Sum-Boxen und den Nodepunkten
\draw[-](Sum1) -- (dot1);
\draw[-](Sum2) -- (dot2);

%Pfeile von den K-Kreisen zu den Sum-Boxen
\draw[->](k1) -- (Sum1)node[midway,below]{$u_1$};
\draw[->](k2) -- (Sum2)node[midway,below]{$u_2$};

%Eckpfeile von den Nodepunkten zu den k-Kreisen
\draw[->] (dot1) -| (k2);
\draw[->] (dot2) -| (k1);

\end{tikzpicture}
\end{document}

遗憾的是 imgur 拒绝了我的截图

答案2

对于您的图像,我将按以下方式编写代码:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning, quotes}

\begin{document}
    \begin{tikzpicture}[semithick,
          auto = right,
             > = Stealth,
 node distance = 6mm and 8mm,
    box/.style = {rectangle, draw, hick, minimum size=6ex},
    dot/.style = {circle, fill, minimum size=3pt,
                 inner sep = 0, outer sep=0pt,
                 node contents={}},
  circ/.style = {circle, draw, thick, minimum size=6ex, inner sep=0pt},
    ]
    % first line
\coordinate (in1);
\node (k1)      [plus,right=of in1]     {$k_1$};
\node (Sum1)    [box, right=of k1]      {$\sum_{1}^{}$};
\node(dot1)     [dot, right=of Sum1,label=below:$y_1$];
% second line
\node (Sum2)    [box, below=of Sum1]    {$\sum_{2}^{}$};
\node (k2)      [plus,right=of Sum2]     {$k_2$};
\node(dot2)     [dot, left =of Sum2, label=above:$y_2$];
\coordinate[right=of k2]  (in2);
% lines in the first line
\draw[->]   (in1)   edge["$v_1$"]    (k1)
            (k1)    edge["$u_1$"]   (Sum1)
            (Sum1) -|   (k2);
% loop on top
\draw[->]   (dot1) -- ++ (0,1) -| (k1);
% lines in the second line
\draw[->]   (in2)   edge["$v_2$" ']    (k2)
            (k2)    edge["$u_2$" ']   (Sum2)
            (Sum2) -|   (k1);
% loop on bottom
\draw[->]   (dot2) -- ++ (0,-1) -| (k2);
\end{tikzpicture}
\end{document}
  • 代码更短
  • 用于坐标\coordinate(用于两个输入)
  • “黑点”被重命名为更短的“点”。由于它们始终为空,因此添加了样式node content={}。除此之外,还设置了outer sep=0pt。这样就不需要从它们的中心画线,因为它们会接触dot
  • “plus” 更名为“circ”
  • “circle” 被删除,因为:
    • 它没有被使用,
    • 它有一个为形状“圆形”保留的名称(这可能会引起混淆tikz
  • 定位使用tikz库提供的语法positioning。这样就变得全部xshift多余yshift,因此从代码中删除

在此处输入图片描述

相关内容