[Tex/LaTex] Boxes within a Dotted Box

boxesdiagrams

How do I create the dotted box? For the rest of the diagram I used a matrix, but I'm having trouble creating that box. Here's the code I used.

\begin{center}
$\begin{matrix}
$ x(n)$\rightarrow \boxed{T} \rightarrow \boxed{[ \hspace{0.25 cm}]^2} \rightarrow &\bigoplus& \rightarrow T[x(n)]$ $\\
$$&\uparrow&$ $\\
$$& 7&$
$ \end{matrix} $
\end{center}

Best Answer

Two approaches:

enter image description here

  1. The first one uses your code (slightly modified) and the tikzmark library from TikZ to place some marks in the diagram; those marks are then used to draw the dashed box (the document needs to be processed twice to stabilize).

  2. The whole diagram is drawn using TikZ; I used a chain, but other approaches are possible, of course. Then the fit library was used to draw the dashed box.

The code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{tikzmark,chains,fit,positioning}

\begin{document}

\[
\begin{matrix}
 x(n)\rightarrow\tikzmark{start}\boxed{T} \rightarrow \boxed{[ \hspace{0.25 cm}]^2} \rightarrow & \bigotimes\tikzmark{end} & \rightarrow T[x(n)] \\
&\uparrow& \\
& 7&
\end{matrix}
\]

\begin{tikzpicture}[remember picture,overlay]
\draw[dashed]
  ([shift={(-8pt,-1cm)}]pic cs:start) 
    rectangle
  ([shift={(15pt,0.7cm)}]pic cs:end); 
\end{tikzpicture}

\[
\begin{tikzpicture}[
  start chain,
  every join/.style={->},
  shorten >= 5pt,
  shorten <= 5pt,
  node distance=0.8cm and 0.8cm
]
\node[on chain,join] {$x(n)$};
\node[draw,on chain,join] (T) {$T$};
\node[draw,on chain,join] {$[\hspace{0.25 cm}]^2$}; 
\node[draw,circle,on chain,join] (otimes) {$\times$};
\node[on chain,join] {$T[x(n)]$};
\node[below=of otimes] (seven) {$7$};
\draw[->] (seven) -- (otimes); 
\node[draw,inner xsep=12pt,dashed,fit={(T) (otimes) (seven)}] {};
\end{tikzpicture}
\]

\end{document}
Related Question