# Recreating this TikZ image

I need to recreate the following image in TikZ.

I'm able to draw the boxes using the following TikZ code, but I'm unable to correctly place the underbraces and the symbols.

\begin{figure}[H]
\begin{tikzpicture}
\draw (0,0) -- (1.6,0) -- (1.6,1.3) -- (0,1.3) -- (0,0);
\draw (1.7,0) -- (3.3,0) -- (3.3,1.3) -- (1.7,1.3) -- (1.7,0);
\draw (3.4,0) -- (5,0) -- (5,1.3) -- (3.4,1.3) -- (3.4,0);
\draw (5.1,0) -- (6.7,0) -- (6.7,1.3) -- (5.1,1.3) -- (5.1,0);

\draw (0.5,0.21) -- (1.5,0.21);
\draw (0.5,0.42) -- (1.5,0.42);
\draw (0.5,0.63) -- (1.5,0.63);
\draw (0.5,0.84) -- (1.5,0.84);
\draw (0.5,1.06) -- (1.5,1.06);

\draw (1.8,0.21) -- (3.2,0.21);
\draw (1.8,0.42) -- (3.2,0.42);
\draw (1.8,0.63) -- (3.2,0.63);
\draw (1.8,0.84) -- (3.2,0.84);
\draw (1.8,1.06) -- (3.2,1.06);

\draw (3.5,0.21) -- (4.9,0.21);
\draw (3.5,0.42) -- (4.9,0.42);
\draw (3.5,0.63) -- (4.9,0.63);
\draw (3.5,0.84) -- (4.9,0.84);
\draw (3.5,1.06) -- (4.9,1.06);

\draw (5.2,0.21) -- (6.6,0.21);
\draw (5.2,0.42) -- (6.6,0.42);
\draw (5.2,0.63) -- (6.6,0.63);
\draw (5.2,0.84) -- (6.6,0.84);
\draw (5.2,1.06) -- (6.6,1.06);
\end{tikzpicture}


## 3 Answers

It's too late in the evening to add a lot of explanations, but I'm adding a completely different suggestion for how to draw this. It is kind of quick and dirty, and could probably be written a lot better.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{
fulllinebox/.pic={
\node (-frame) at (0,0) [above right,draw,minimum width=1.6cm,minimum height=1.3cm] {};
\foreach \y in {0.167,0.334,...,1}
\draw (-frame.south west) ++(0.1cm,1.3cm*\y) -- +(1.4cm,0);
},
halflinebox/.pic={
\node (-frame) at (0,0)  [above right,draw,minimum width=1.6cm,minimum height=1.3cm] {};
\foreach \y in {0.167,0.334,...,1}
\draw (-frame.south west) ++(0.7cm,1.3cm*\y) -- +(0.8cm,0);
}
}
\begin{document}
\begin{tikzpicture}[decoration={brace,mirror,amplitude=5pt}]
\pic (1) {halflinebox};
\pic (2) at ([xshift=0.2cm]1-frame.south east) {fulllinebox};
\pic (3) at ([xshift=0.2cm]2-frame.south east) {fulllinebox};
\pic (4) at ([xshift=0.2cm]3-frame.south east) {fulllinebox};

\draw [decorate] (1-frame.south west) ++(0.1cm,-1pt) -- node[below=5pt]{$S_m$} ++(1.4cm,0);
\draw [decorate] (4-frame.south west) ++(0.1cm,-1pt) -- node[below=5pt]{$S_1$} ++(1.4cm,0);

\path (2-frame.south east) --node[below=9pt] {$\dots$} (3-frame.south west);

\draw [latex-latex,shorten >=0.05cm,shorten <=0.05cm] ([yshift=0.1cm]4-frame.north west) -- node[above]{$l$} ([yshift=0.1cm]4-frame.north east);

\node [right,align=center] at (4-frame.east) {$x_1$\\$\vdots$\\$x_n$};
\end{tikzpicture}
\end{document}


Coordinates are a way to save the position of a coordinate to use it later. The decorations.pathreplacing library contains a brace decoration, which has to be mirrored here (or you could reverse the order of the points specified). The calc library allows you to compute with (abstact) coordinates, like adding a certain amount (($(N)+(x,y)$)) or to specify a point a certain fraction along the way betweeen two points (($(V)!x!(W)$)). stelth is a certain kind of arrow tip, there are many others, see the manual or here.

## Code

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{calc, decorations.pathreplacing}

\begin{document}

\begin{tikzpicture}[decoration={brace, mirror}]
\draw (0,0) coordinate (A) -- (1.6,0) coordinate (B) -- (1.6,1.3) -- (0,1.3)  -- cycle;
\draw (1.7,0) -- (3.3,0) coordinate (C) -- (3.3,1.3) -- (1.7,1.3) -- cycle;
\draw (3.4,0) coordinate (D) -- (5,0) -- (5,1.3) -- (3.4,1.3) -- cycle;
\draw (5.1,0) coordinate (E) -- (6.7,0) coordinate (F) -- (6.7,1.3) coordinate (G) -- (5.1,1.3) coordinate (H) -- cycle;

\draw (0.5,0.21) -- (1.5,0.21);
\draw (0.5,0.42) -- (1.5,0.42);
\draw (0.5,0.63) -- (1.5,0.63);
\draw (0.5,0.84) -- (1.5,0.84);
\draw (0.5,1.06) -- (1.5,1.06);

\draw (1.8,0.21) -- (3.2,0.21);
\draw (1.8,0.42) -- (3.2,0.42);
\draw (1.8,0.63) -- (3.2,0.63);
\draw (1.8,0.84) -- (3.2,0.84);
\draw (1.8,1.06) -- (3.2,1.06);

\draw (3.5,0.21) -- (4.9,0.21);
\draw (3.5,0.42) -- (4.9,0.42);
\draw (3.5,0.63) -- (4.9,0.63);
\draw (3.5,0.84) -- (4.9,0.84);
\draw (3.5,1.06) -- (4.9,1.06);

\draw (5.2,0.21) -- (6.6,0.21);
\draw (5.2,0.42) -- (6.6,0.42);
\draw (5.2,0.63) -- (6.6,0.63);
\draw (5.2,0.84) -- (6.6,0.84);
\draw (5.2,1.06) -- (6.6,1.06);

\draw[decorate] ($(A)+(0,-0.1)$) -- ($(B)+(0,-0.1)$);
\node[below] at ($(A)!0.5!(B)+(0,-0.2)$) {$\Delta\epsilon$};

\node[below] at ($(C)!0.5!(D)$) {$\dots$};

\draw[decorate] ($(E)+(0,-0.1)$) -- ($(F)+(0,-0.1)$);
\node[below] at ($(E)!0.5!(F)+(0,-0.2)$) {$\Omega\varphi$};

\node[right] at (G) {$\tau_{\beta}$};
\node[right] at ($(F)!0.55!(G)$) {$\vdots$};
\node[right] at (F) {$\tau_{\nu}$};

\draw[stealth-stealth] ($(G)+(0,0.1)$) -- ($(H)+(0,0.1)$);

\end{tikzpicture}

\end{document}


## Output

• Also, as the lines all appear to be the same length, you could have a look at \foreach and the syntax for relative coordinates (\draw (2,1) -- ++ (1,1);) – Tom Bombadil Nov 26 '15 at 23:21

One more alternative:

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{calc, chains, decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}[
node distance = 2mm,
start chain = going right,
A/.style = {draw, minimum width=16mm, minimum height=13mm,
inner sep=1mm, node contents={},
on chain},
B/.style = {decorate,
decoration={brace, raise=1mm, mirror,
pre=moveto, pre length=1mm,  post=moveto,post length=1mm},
thick},
arr/.style = {thick, shorten < = 1mm, shorten > = 1mm}
]
\node (n1)  [A];
\foreach \i in {2,5,8,11}
\draw[arr,shorten <=8mm] ($(n1.south west) + (0,\i mm)$) -- + (16mm,0);
\node (n2)  [A];
\foreach \i in {2,5,8,11}
\draw[arr]  ($(n2.south west) + (0,\i mm)$) -- + (16mm,0);
\node (n3)  [A];
\foreach \i in {2,5,8,11}
\draw[arr]  ($(n3.south west) + (0,\i mm)$) -- + (16mm,0);
\node (n4)  [A];
\foreach \i in {2,5,8,11}
\draw[arr]  ($(n4.south west) + (0,\i mm)$) -- + (16mm,0);

\draw[B] (n1.south west) -- node[below=2mm]{$S_m$} (n1.south east);
\draw[B] (n4.south west) -- node[below=2mm]{$S_1$} (n4.south east);

\draw[stealth-stealth,shorten <=1mm, shorten >=1mm]
([yshift=2mm] n4.north west) -- node[above] {$l$} + (16mm,0);

\node[align=left,right=0mm of n4]   {$x_1$\\$\vdots$\\$x_n$};
\end{tikzpicture}
\end{document}


In my example I employ additional package chains for set nodes in chain. For drawing lines in nodes the \foreach loop is used. For simplifying of lines drawing in nodes they are shorten by option shorten >=..., so for the coordinates can be used left and right node's borders.

• What is your very last sentence supposed to say? – Tom Bombadil Nov 27 '15 at 1:02
• @TomBombadil, ups, there are missing "simple to", When I wrote this sentence, here was already time for sleep :-( I will correct it. – Zarko Nov 27 '15 at 8:32
• Ah, much clearer. I was also quite tired and wasn't sure if it was just my sleep-deprived brain that had trouble understanding you ;-) – Tom Bombadil Nov 27 '15 at 14:03