编辑

编辑

我想连接一些节点,但不连接直线,而是连接 90 度角,并使其更圆。到目前为止,我有以下几点:

\usetikzlibrary{arrows,positioning,shapes.symbols,shapes.callouts,patterns}

\begin{tikzpicture}

\node[draw] (a0) {A0};
\node[draw, right=of a0] (b0) {B0};
\node[draw, below right=of b0] (c) {C};
\node[draw, right=of c] (d) {D};
\node[draw, below left=of c] (bn) {Bn};
\node[draw, left=of bn] (an) {An};

\draw[-latex, ->] ([yshift=5]a0.east) -- ([yshift=5]b0.west);
\draw[-latex, ->] ([yshift=2.5]a0.east) -- ([yshift=2.5]b0.west);
\draw[-latex, <-] ([yshift=-2.5]a0.east) -- ([yshift=-2.5]b0.west);
\draw[-latex, <-] ([yshift=-5]a0.east) -- ([yshift=-5]b0.west);

\draw[-latex, ->] ([yshift=5]an.east) -- ([yshift=5]bn.west);
\draw[-latex, ->] ([yshift=2.5]an.east) -- ([yshift=2.5]bn.west);
\draw[-latex, <-] ([yshift=-2.5]an.east) -- ([yshift=-2.5]bn.west);
\draw[-latex, <-] ([yshift=-5]an.east) -- ([yshift=-5]bn.west);

\draw[-latex, ->] ([yshift=2.5]b0.east) -| ([yshift=5]c.west);
\draw[-latex, <-] ([yshift=-2.5]b0.east) -| ([yshift=2.5]c.west);

\draw[-latex, ->] ([yshift=2.5]bn.east) -| ([yshift=-2.5]c.west);
\draw[-latex, <-] ([yshift=-2.5]bn.east) -| ([yshift=-5]c.west);

\draw[-latex, ->] ([yshift=2.5]c.east) -- ([yshift=2.5]d.west);
\draw[-latex, <-] ([yshift=-2.5]c.east) -- ([yshift=-2.5]d.west);

\end{tikzpicture}

看起来像:

在此处输入图片描述

然而,从 B0 到 C 的线条像现在这样在中间向下折断,然后向左转到 C,并且带有圆角。

我应该在每一\draw行添加什么?

谢谢您的帮助

答案1

您必须在距起始节点一定距离处添加一个辅助点,然后才能使用|-参数。对于圆角,嗯...只需添加rounded corners
请注意,当您编写时[-latex, ->],您会用普通箭头覆盖您的乳胶箭头,这就是为什么最好将箭头类型定义到声明中tikzpicture(参见下面的代码)。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes.symbols,shapes.callouts,patterns,fit}

\begin{document}

    \begin{tikzpicture}[>=latex]
    
        \node[draw] (a0) {A0};
        \node[draw, right=of a0] (b0) {B0};
        \node[draw, below right=of b0] (c) {C};
        \node[draw, right=of c] (d) {D};
        \node[draw, below left=of c] (bn) {Bn};
        \node[draw, left=of bn] (an) {An};
        
        \draw[->] ([yshift=5]a0.east) -- ([yshift=5]b0.west);
        \draw[->] ([yshift=2.5]a0.east) -- ([yshift=2.5]b0.west);
        \draw[<-] ([yshift=-2.5]a0.east) -- ([yshift=-2.5]b0.west);
        \draw[<-] ([yshift=-5]a0.east) -- ([yshift=-5]b0.west);
        
        \draw[->] ([yshift=5]an.east) -- ([yshift=5]bn.west);
        \draw[->] ([yshift=2.5]an.east) -- ([yshift=2.5]bn.west);
        \draw[<-] ([yshift=-2.5]an.east) -- ([yshift=-2.5]bn.west);
        \draw[<-] ([yshift=-5]an.east) -- ([yshift=-5]bn.west);
        
        \draw[->,rounded corners=1pt] ([yshift=2.5]b0.east) --++ (.6,0) |- ([yshift=5]c.west);
        \draw[<-,rounded corners=1pt] ([yshift=-2.5]b0.east)--++ (.4,0) |- ([yshift=2.5]c.west);
        
        \draw[->,rounded corners=1pt] ([yshift=2.5]bn.east) --++ (.4,0) |- ([yshift=-2.5]c.west);
        \draw[<-,rounded corners=1pt] ([yshift=-2.5]bn.east) --++ (.6,0) |- ([yshift=-5]c.west);
        
        \draw[->] ([yshift=2.5]c.east) -- ([yshift=2.5]d.west);
        \draw[<-] ([yshift=-2.5]c.east) -- ([yshift=-2.5]d.west);

        \node[fit=(a0)(an)(d),draw,rounded corners=1pt]{}; % <-- This to add the bounding box around the nodes.
    \end{tikzpicture}

\end{document}

编辑

根据要求,我使用库在节点周围添加了一个边界框fit。请注意,您还必须在序言中加载它。

断箭和边界框

相关内容