如何使用 tikz 为流程图绘制任意边界框

如何使用 tikz 为流程图绘制任意边界框

我的流程图如下:

在此处输入图片描述

我需要绘制一个包围 JT、VB、L 和 PM 的边界框。

我的流程图的最小工作示例:

\documentclass[10pt,twocolumn,letterpaper]{article}

\usepackage{times}
\usepackage{epsfig}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}
\usetikzlibrary{calc,positioning, fit}
\usepackage{array}
\usepackage{caption}
\usepackage{tabularx}
\usepackage{adjustbox}


\tikzstyle{process5}=[rectangle,
      draw=blue,
      thick,
      fill=blue!20,
      text width=4em,
      align=center,
      rounded corners,
      minimum height=3em]
\tikzstyle{arrow}=[thick,->,>=stealth]

\tikzstyle{process6}=[rectangle,
      draw=red,
      thick,
      fill=red!20,
      text width=4em,
      align=center,
      rounded corners,
      minimum height=3em]
\tikzstyle{arrow}=[thick,->,>=stealth]

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[node distance=1cm]
\node(GUI) [process5]{GUI };
\node(JA) [process6, right of=GUI, xshift=1.8cm]{JA};
\node(JT) [process5, below of=GUI, yshift=-1.0cm]{JT};
\node(BM) [process5, left of=JT,xshift=-1.5cm, yshift=-0.6cm]{BM};
\node(L) [process5, below of=JT,yshift=-2.0cm]{L};
\node(VB) [process5, left of=L,xshift=-1.5cm, yshift=0cm]{VB};
\node(PM) [process5, below of=L,yshift=-1.0cm]{PM};
\node(R) [process6, right of=PM, xshift=1.8cm]{R};

\node[draw,blue,inner sep=7mm,label=below:LH,fit=(GUI) (BM)  (GUI)     (PM)] {};

\node[draw,red,inner sep=2mm,label=below:OG,fit=(JT) (JT) (PM) (PM)] {};


\draw [arrow] (GUI) -- (JT) node [pos=0.4,right] {$\vec{\theta}$};
\draw [arrow] (JA) -- (GUI);
\draw [arrow] (JT) -- (L);
\draw[black,arrow] let \p1=(BM), \p2=(JT) in (BM) -- (1.0*\x1,0.65*\y1) -- ([yshift=0.3cm]JT.west) node [pos=0.5,above] {sk};
\draw [arrow] (BM) -- (VB) node [pos=0.25,right] {M};
\draw[black,arrow] let \p1=(VB), \p2=(PM) in (VB) -- (1.0*\x1,1.36*\y1) -- ([yshift=0.2cm]PM.west) node [pos=0.55,above]     {($V, T$)};
\draw[black,arrow] let \p1=(GUI), \p2=(PM) in (GUI) -- (-3.5,0)  -- (-3.5,-7.3)-- ([yshift=-0.3cm]PM.west) node [pos=0.75,above] {$L$};
\draw [arrow] (PM) -- (R);
\draw [arrow] ([yshift=-0.4cm]L.west) -- ([yshift=-0.4cm]VB.east) node [pos=0.5,above] {$Vout$};
\draw [arrow] ([yshift=0.4cm]VB.east) -- ([yshift=0.4cm]L.west) node [pos=0.5,above] {$Vin$};

\end{tikzpicture}
\caption{LHR}
\label{fig:flow}
\end{figure}

\end{document}

答案1

由于您可能想要绕过BM节点,因此您需要手动执行此操作,而无需使用库fit。因此添加

\draw [red, thick,inner sep=2mm]
       ([shift={( 0.5em, 1.0ex)}]JT.north east)
    -- ([shift={(-0.5em, 1.0ex)}]JT.north west)
    |- ([shift={(-0.3em, 1.7ex)}]VB.north west)
    |- ([shift={( 0.5em,-1.0ex)}]PM.south east)
    -- cycle
    ;

产量

在此处输入图片描述

笔记:

代码:

\documentclass{article}

\usepackage{times}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}
\usetikzlibrary{calc,positioning, fit}
\usepackage{caption}


\tikzset{process5/.style={rectangle,
      draw=blue,
      thick,
      fill=blue!20,
      text width=4em,
      align=center,
      rounded corners,
      minimum height=3em}}
\tikzset{arrow/.style={thick,->,>=stealth}}

\tikzset{process6/.style={rectangle,
      draw=red,
      thick,
      fill=red!20,
      text width=4em,
      align=center,
      rounded corners,
      minimum height=3em}}
\tikzset{arrow/.style={thick,->,>=stealth}}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[node distance=1cm]
\node(GUI) [process5]{GUI };
\node(JA) [process6, right of=GUI, xshift=1.8cm]{JA};
\node(JT) [process5, below of=GUI, yshift=-1.0cm]{JT};
\node(BM) [process5, left of=JT,xshift=-1.5cm, yshift=-0.6cm]{BM};
\node(L) [process5, below of=JT,yshift=-2.0cm]{L};
\node(VB) [process5, left of=L,xshift=-1.5cm, yshift=0cm]{VB};
\node(PM) [process5, below of=L,yshift=-1.0cm]{PM};
\node(R) [process6, right of=PM, xshift=1.8cm]{R};

\node[draw,blue,inner sep=7mm,label=below:LH,fit=(GUI) (BM)  (GUI)     (PM)] {};

%\node[draw,red,inner sep=2mm,label=below:OG,fit=(JT) (JT) (PM) (PM)] {};

\draw [red, thick,inner sep=2mm]
       ([shift={( 0.5em, 1.0ex)}]JT.north east)
    -- ([shift={(-0.5em, 1.0ex)}]JT.north west)
    |- ([shift={(-0.3em, 1.7ex)}]VB.north west)
    |- ([shift={( 0.5em,-1.0ex)}]PM.south east)
    -- cycle
    ;

\draw [arrow] (GUI) -- (JT) node [pos=0.4,right] {$\vec{\theta}$};
\draw [arrow] (JA) -- (GUI);
\draw [arrow] (JT) -- (L);
\draw[black,arrow] let \p1=(BM), \p2=(JT) in (BM) -- (1.0*\x1,0.65*\y1) -- ([yshift=0.3cm]JT.west) node [pos=0.5,above] {sk};
\draw [arrow] (BM) -- (VB) node [pos=0.25,right] {M};
\draw[black,arrow] let \p1=(VB), \p2=(PM) in (VB) -- (1.0*\x1,1.36*\y1) -- ([yshift=0.2cm]PM.west) node [pos=0.55,above]     {($V, T$)};
\draw[black,arrow] let \p1=(GUI), \p2=(PM) in (GUI) -- (-3.5,0)  -- (-3.5,-7.3)-- ([yshift=-0.3cm]PM.west) node [pos=0.75,above] {$L$};
\draw [arrow] (PM) -- (R);
\draw [arrow] ([yshift=-0.4cm]L.west) -- ([yshift=-0.4cm]VB.east) node [pos=0.5,above] {$Vout$};
\draw [arrow] ([yshift=0.4cm]VB.east) -- ([yshift=0.4cm]L.west) node [pos=0.5,above] {$Vin$};

\end{tikzpicture}
\caption{LHR}
\label{fig:flow}
\end{figure}

\end{document}

相关内容