1

I know basic LaTeX I tried to draw a block diagram similar to the one shown in diagram but I am unable to do it as one block is inside another I am getting problem in rendering. Please suggest any easy way to draw such block diagram. Thank youenter image description here

closed as unclear what you're asking by Martin Schröder, Svend Tveskæg, Mensch, Przemysław Scherwentke, Jesse Dec 24 '15 at 16:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 8
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – henry Mar 13 '15 at 13:56
  • 1
    Here is an example of a diagram inside other boxes. texample.net/tikz/examples/noise-shaper – R. Schumacher Mar 13 '15 at 14:02
18
\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}

enter image description here

This one is for Paul:

\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}

enter image description here

With filling it looks like this:

\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}

enter image description here

  • 6
    You're missing the spellchecker's zig-zag red underline... ;-) – Paul Gessler Mar 13 '15 at 14:22
  • 2
    @PaulGessler: Oh No!. I am caught. :-) – user11232 Mar 13 '15 at 14:23
  • And I voted for that... :-( – LaRiFaRi Mar 13 '15 at 14:24
  • 1
    @PaulGessler You got what you asked for :P – user11232 Mar 13 '15 at 14:46
  • Great answer, when I try to add fill color in the fit box, it seems inside box will be in background. how can we just fill it as a background but keep inside box on top layer? e.g. "fill=red!10,fill opacity=0.9" – Beatlej Mar 13 '15 at 22:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.