容器之间的空间以及从块到容器的箭头

容器之间的空间以及从块到容器的箭头

我正在尝试构建一个框图并迄今为止实现如下目标。

在此处输入图片描述

梅威瑟:

\documentclass{article}
\usepackage[utf8]{inputenc}
\title{system overview}
\author{Paari Vendhan}
\date{November 2018}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, arrows.meta, fit,backgrounds, positioning, calc}


\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm,  draw=black, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{container1} = [draw, rectangle, inner sep=0.3cm, fill=gray!20,minimum height=5cm]


\tikzset{
  mybackground/.style={execute at end picture={
      \begin{scope}[on background layer]
        \node[] at (current bounding box.north){\bottom{1cm} #1};
        \end{scope}
    }},
}


\begin{document}

\maketitle

\section{Flowchart}

    \begin{figure}[!h]

        \begin{tikzpicture}[%
            every path/.style={thick, shorten >=2pt, shorten <=2pt},
            node distance=2cm
          ]
            \node (pro1) [process] {K};                 
            \node (pro2) [process, below of=pro1, yshift=-0.5cm] {A};
            \node (pro3) [process, right of=pro2, xshift = 2cm, yshift=1.25cm] {B};     
            \node (pro4) [process, below of=pro2, yshift=-0.5cm] {C};
            \node (pro5) [process, below of=pro4, yshift=-0.5cm] {D};
            \node (pro6) [process, right of=pro5, xshift = 2cm] {E};
            \node (pro7) [process, right of=pro6, xshift = 2cm, yshift=2.5cm] {F};
            \node (pro8) [process, right of=pro7, xshift = 2cm] {G};
            \node (clo1)[cloud, cloud puffs=15.7, right of=pro1, minimum width=3cm, draw, fill=green!20, xshift=8.25cm] {H};



            \begin{scope}[on background layer]
                \node (block1) [container1,fit= { (pro1) (pro2) (pro4) (pro5) }, ] (container) {};
                \node (block2) [container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (container) {};
                \node (block3) [container1,fit=(pro8), fill=red!10] (container) {};
            \end{scope}


            \draw [arrow] (pro1) -| (pro3);
            \draw [arrow] (pro2) -| (pro3);
            \draw [arrow] (pro5) -- (pro6);
            \draw [arrow] (pro3) -| (pro7);
            \draw [arrow] (pro6) -| (pro7);
%           \draw [arrow] (pro7) -| (clo1);   # needs an offset arrow from pro7
            \draw [arrow] (clo1) -| (pro8);


            \path [draw=black,->, -Stealth] ([xshift=.25cm]pro7.north) |- (clo1.west);

        \end{tikzpicture}   

        \caption{System Overview} \label{fig:sys_ov}

    \end{figure}


\end{document}

问题:
1. 如何增加背景容器之间的空间?我尝试移动,但容器上的块不会随之移动,这使事情变得复杂。2.
箭头并非完全从节点开始,但箭头端点(起点或终点)与块之间存在小间隙)。如何解决?
3. 我无法在块和容器之间绘制箭头。例如,我想将 C 连接到蓝色容器,并将右端的粉红色连接到 C。4
. 另外,我如何让所有容器的高度相同?最小高度会弄乱它们的对齐。

更新 1:
按照安德烈的建议,图片已即兴制作如下。只有两个问题。从 C 到块 1 的箭头应该是直的(从 C 所在的位置,箭头从其右侧发出,直行到右侧的蓝色容器)。另外,另一个箭头应该从 C 的左侧发出,在底部绕一圈到粉红色容器,而不是像下面这样直接。我们怎么做这些?

在此处输入图片描述

更新 2:
更新 1 中的一个上述问题几乎已修复,如下所示。但是,从 C 到蓝色的箭头仍然弯曲,我希望它从 C 直接向右指向蓝色容器。我们该怎么办?

在此处输入图片描述

更新的 MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\title{system overview}
\author{Paari Vendhan}
\date{November 2018}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, arrows.meta, fit,backgrounds, positioning, calc}
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm,  draw=black, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{container1} = [draw, rectangle, inner sep=0.3cm, fill=gray!20,minimum height=9cm]
\tikzstyle{line} = [draw, -latex']
\tikzset{
  mybackground/.style={execute at end picture={
      \begin{scope}[on background layer]
        \node[] at (current bounding box.north){\bottom{1cm} #1};
        \end{scope}
    }},
}

\begin{document}
\maketitle
\section{Flowchart}

    \begin{figure}[!htp]

        \begin{tikzpicture}[%
            every path/.style={thick,% shorten >=pt, shorten <=2pt
            },
            node distance=2cm,
          ]

            \node [process] (pro1) at (0,0) {K};                 
            \node [process](pro2) [below=1cm of pro1 ] {A};
            \node [process] (pro3) [right=1cm of pro2, yshift=1cm] {B};     
            \node [process] (pro4) [below= 1cm of pro2] {C};
            \node [process](pro5) [below= 1cm of pro4] {D};
            \node [process](pro6) [right =1cm of pro5,yshift=1cm] {E};
            \node [process](pro7) [right of =pro6, yshift=2cm] {F};
            \node [process](pro8) [right =1cm of pro7] {G};
            \node (clo1)[cloud, cloud puffs=15.7, above=4.5cm of pro7,xshift=2.5cm, minimum width=3cm, draw, fill=green!20] {H};


            \begin{scope}[on background layer]
                \node  [container1,fit= { (pro1) (pro2) (pro4) (pro5) }] (block1) {};
                \node  [container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (block2) {};
                \node  [container1,fit=(pro8), fill=red!10] (block3) {};
                \path [arrow,out=0,in=180] (pro4)edge(block2);
                \path[line] (pro4) -| ([xshift=-0.5cm,yshift=-1.5cm]pro5.south west) -| (block3);
            \end{scope}

            \draw [arrow] (pro1) -| (pro3);
            \draw [arrow] (pro2) -| (pro3);
            \draw [arrow] (pro5) -| (pro6);
            \draw [arrow] (pro3) -| (pro7);
            \draw [arrow] (pro6) -| (pro7);
%           \draw [arrow] (pro7) -| (clo1);   # needs an offset arrow from pro7
            \draw [arrow] (clo1) -| (pro8);

            \path [draw=black,->, -Stealth] ([xshift=.25cm]pro7.north) |- (clo1.west);
        \end{tikzpicture}   
        \caption{System Overview} \label{fig:sys_ov}

    \end{figure}
\end{document}

答案1

您在网上找到的代码包含很多语法错误。我已更正它们。

这似乎不是你的问题,因为问题 #2 是由shorten手册 3.01a 中未记录的操作引起的。你可以找到关于此的文档shorten。你可以在版本 1.18 手册的第 109 页中http://www.bu.edu/math/files/2013/08/tikzpgfmanual.pdf

删除它就行了。

\begin{tikzpicture}[%
            every path/.style={thick, %shorten >=2pt, shorten <=2pt
            },node distance=2cm
          ]

要使节点高度相同,只需修改样式即可

\tikzstyle{container1} =[draw, rectangle, inner sep=0.3cm, fill=gray!20,minimum height=5cm]

并替换minimum height=5cmminimum height=9cm

因此是不正确的:

\node (pro1)[process] {K};

您必须首先给出坐标。这将给出:

\node[process] (pro1) at (0,0) {K};

然后此代码加载positioning库但不使用它的功能。我用这个库的语法将节点重写(pro1)(clo1)

    \node [process](pro1) at (0,0) {K};                 
    \node [process](pro2) [below=1cm of pro1 ] {A};
    \node [process](pro3) [above right= 0cm and 2cm of pro2] {B};     
    \node [process](pro4) [below= 1cm of pro2] {C};
    \node [process](pro5) [below= 1cm of pro4] {D};
    \node [process](pro6) [above right =0cm and 2cm of pro5] {E};
    \node [process](pro7) [above right= 1cm and 0 cm of pro6] {F};
    \node [process](pro8) [right =2cm of pro7] {G};
    \node (clo1)[cloud, cloud puffs=15.7, above right=4.5cm and 0cm of pro7, minimum width=2.5cm, draw, fill=green!20] {H};

为了在块之间留出空间,我只是将节点之间的距离拉BE更远。

包含块的节点的语法也不正确。通过编写

 \node (block1)[container1,fit= { (pro1) (pro2) (pro2) (pro4) (pro5) }, ] (container) {};

你命名节点(container)而不是(block1)

在下一行中,使用相同的名称命名第二个块(container)

\node (block2)[container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (container) {};

写吧

\node[container1,fit= { (pro1) (pro2) (pro2) (pro4) (pro5) }] (block1) {};
\node[container1,fit=(pro3) (pro7) (pro7) (pro6), fill=cyan!20] (block2) {};`

以便块被正确命名。

要创建从下一个块的箭头C,只需在现有范围视图中执行此操作:

\begin{scope}[on background layer]
                \node  [container1,fit= { (pro1) (pro2) (pro4) (pro5) }] (block1) {};
                \node  [container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (block2) {};
                \node  [container1,fit=(pro8), fill=red!10] (block3) {};
                \path [arrow,out=0,in=180] (pro4)edge(block2);
            \end{scope}

更新:

为了制作一个绕着方块旋转的箭头,我在左下角创建了一个名为 (inter) 的点。然后我制作了箭头。

 \node [left=1cm of pro4,yshift=-4.3cm](inter){};
 \path [arrow,draw,inner sep=0pt,outer sep=0pt] (pro4)-|(inter.center)-|(block3);

为了使箭头变直,我通过水平移动点 C 进行调整,并通过反复试验找到了正确的长度。

 \path [arrow,draw] (pro4.east)--([xshift=2.5cm]pro4.east);

我还将节点H向右移动以使其更美观。

更新 2:

为了使图形包含在文章类的页面中,只需减少矩形和文本的宽度(2 厘米而不是 3 厘米)。

\tikzstyle{process} = [rectangle, minimum width=2cm, minimum height=1cm, text centered, text width=2cm,  draw=black, fill=orange!30]

流程图

\documentclass{article}
\usepackage[utf8]{inputenc}
%\usepackage[margin=1cm]{geometry}
\title{system overview}
\author{Paari Vendhan}
\date{November 2018}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, arrows.meta, fit,backgrounds, positioning, calc}
\tikzstyle{process} = [rectangle, minimum width=2cm, minimum height=1cm, text centered, text width=2cm,  draw=black, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{container1} = [draw, rectangle, inner sep=0.3cm, fill=gray!20,minimum height=9cm]
\tikzset{
  mybackground/.style={execute at end picture={
      \begin{scope}[on background layer]
        \node[] at (current bounding box.north){\bottom{1cm} #1};
        \end{scope}
    }},
}

\begin{document}
\maketitle
\section{Flowchart}

    \begin{figure}[!h]

        \begin{tikzpicture}[%
            every path/.style={thick,% shorten >=pt, shorten <=2pt
            },
          ]
            \node [process](pro1) at (0,0) {K};                 
            \node [process](pro2) [below=1cm of pro1 ] {A};
            \node [process](pro3) [above right= 0cm and 2cm of pro2] {B};     
            \node [process](pro4) [below= 1cm of pro2] {C};
            \node [process](pro5) [below= 1cm of pro4] {D};
            \node [process](pro6) [above right =0cm and 2cm of pro5] {E};
            \node [process](pro7) [above right= 1cm and 0 cm of pro6] {F};
            \node [process](pro8) [right =2cm of pro7] {G};
            \node (clo1)[cloud, cloud puffs=15.7, above right=4.5cm and 0cm of pro7, minimum width=2.5cm, draw, fill=green!20] {H};

            \begin{scope}[on background layer]
                \node  [container1,fit= { (pro1) (pro2) (pro4) (pro5) }] (block1) {};
                \node  [container1,fit=(pro3) (pro7) (pro6), fill=cyan!20] (block2) {};
                \node  [container1,fit=(pro8), fill=red!10] (block3) {};
                \path [arrow,draw] (pro4.east)--([xshift=2.5cm]pro4.east);
                \node [left=1cm of pro4,yshift=-4.3cm](inter){};
                \path [arrow,draw,inner sep=0pt,outer sep=0pt] (pro4)-|(inter.center)-|(block3);
            \end{scope}

            \draw [arrow] (pro1) -| (pro3);
            \draw [arrow] (pro2) -| (pro3);
            \draw [arrow] (pro5) -| (pro6);
            \draw [arrow] (pro3) -| (pro7);
            \draw [arrow] (pro6) -| (pro7);
%           \draw [arrow] (pro7) -| (clo1);   # needs an offset arrow from pro7
            \draw [arrow] (clo1) -| (pro8);

            \path [draw=black,->, -Stealth] ([xshift=.25cm]pro7.north) |- (clo1.west);
        \end{tikzpicture}   
        \caption{System Overview} \label{fig:sys_ov}
    \end{figure}
\end{document}

使用 www.DeepL.com/Translator 翻译

相关内容