如何在 LaTeX 中绘制这样的框图

如何在 LaTeX 中绘制这样的框图

我懂基本的 LaTeX,我尝试绘制一个类似于图中所示的框图,但我无法做到,因为一个块在另一个块里面,我在渲染时遇到了问题。请建议任何绘制此类框图的简单方法。谢谢在此处输入图片描述

答案1

\documentclass[tikz,border=4mm]{standalone}
\usetikzlibrary{positioning,fit,calc}
\tikzset{block/.style={draw,thick,text width=2cm,minimum height=1cm,align=center},
         line/.style={-latex}
}
\begin{document}

\begin{tikzpicture}
  \node[block] (a) {Dam};
  \node[block,right=of a] (b) {Checkdam};
  \node[block,right= 3cm of b] (c) {Checkdam};
  \node[block,right=of c] (d) {Dam};
  \node[block] (e) at ([yshift=-2cm]$(b)!0.5!(c)$) {Gate};
  \node[draw,inner xsep=5mm,inner ysep=8mm,fit=(a)(b),label={130:A}](f){};
  \node[draw,inner xsep=5mm,inner ysep=8mm,fit=(c)(d),label={50:B}]{};
  \node[draw,inner xsep=5mm,inner ysep=6mm,fit=(b)(c)]{};
  \draw[line] (a)-- (b);
  \draw[line] (b) -- (f.east);
  \draw[line] (f.east) -- (c)node[pos=0.4,above]{flow};
  \draw[line] (c)-- (d);
  \draw[line] (e)-- ($(b)!0.5!(c)$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

这是献给保罗的:

\documentclass[tikz,border=4mm]{standalone}
\usepackage[normalem]{ulem}
\usetikzlibrary{positioning,fit,calc}
\tikzset{block/.style={draw,thick,text width=2cm,minimum height=1cm,align=center},
         line/.style={-latex}
}
\makeatletter
\def\ruwave{\bgroup \markoverwith{\lower3.5\p@\hbox{\textcolor{red}{\sixly \char58}}}\ULon}
\font\sixly=lasy6
\makeatother
\begin{document}

\begin{tikzpicture}
  \node[block] (a) {Dam};
  \node[block,right=of a] (b) {\ruwave{Checkdam}};
  \node[block,right= 3cm of b] (c) {\ruwave{Checkdam}};
  \node[block,right=of c] (d) {Dam};
  \node[block] (e) at ([yshift=-2cm]$(b)!0.5!(c)$) {Gate};
  \node[draw,inner xsep=5mm,inner ysep=8mm,fit=(a)(b),label={130:A}](f){};
  \node[draw,inner xsep=5mm,inner ysep=8mm,fit=(c)(d),label={50:B}]{};
  \node[draw,inner xsep=5mm,inner ysep=6mm,fit=(b)(c)]{};
  \draw[line] (a)-- (b);
  \draw[line] (b) -- (f.east);
  \draw[line] (f.east) -- (c)node[pos=0.4,above]{flow};
  \draw[line] (c)-- (d);
  \draw[line] (e)-- ($(b)!0.5!(c)$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

使用filling 它看起来像这样:

\documentclass[tikz,border=4mm]{standalone}
\usepackage[normalem]{ulem}
\usetikzlibrary{positioning,fit,calc,backgrounds}
\tikzset{block/.style={draw,thick,text width=2cm,minimum height=1cm,align=center},
         line/.style={-latex}
}
\makeatletter
\def\ruwave{\bgroup \markoverwith{\lower3.5\p@\hbox{\textcolor{red}{\sixly \char58}}}\ULon}
\font\sixly=lasy6
\makeatother


\begin{document}
\begin{tikzpicture}
  \node[block] (a) at(0,0) {Dam};
  \node[block,right=of a] (b) {\ruwave{Checkdam}};
  \node[block,right= 3cm of b] (c) {\ruwave{Checkdam}};
  \node[block,right=of c] (d) {Dam};
  \node[block] (e) at ([yshift=-2cm]$(b)!0.5!(c)$) {Gate};
  \begin{scope}[on background layer]
   \node[draw,inner xsep=5mm,inner ysep=6mm,fit=(b)(c),fill=magenta!40]{};
   \node[draw,fill=olive,fill opacity=0.5,inner xsep=5mm,inner
     ysep=8mm,fit=(a)(b),label={130:A}](f){};
  \node[draw,fill=olive,fill opacity=0.5,inner xsep=5mm,inner
     ysep=8mm,fit=(c)(d),label={50:B}]{};
  \end{scope}
  \draw[line] (a)-- (b);
  \draw[line] (b) -- (f.east);
  \draw[line] (f.east) -- (c)node[pos=0.4,above]{flow};
  \draw[line] (c)-- (d);
  \draw[line] (e)-- ($(b)!0.5!(c)$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容