I am trying to create a vertical section with different height blocks and fill each block with different patterns using the following code.
My approach:
I have saved the patterns name as a list of stings in the variable \names and trying to access its elements (\names[\i]) in the \draw command as pattern= \pgfmathparse{\names[\i]}\pgfmathresult.
I am using \foreach loop and in its i th iteration, it should be providing i th pattern from the list.
Previous solutions were suggested in this post and this post, however, these didn't work.
In essence, I am facing a problem in passing down the pattern to the draw command. Alternatively, is there any way to automatically change the fill pattern in some given sequence?
The figure should look as shown below.
\\documentclass[10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\def\zthick{{1, 0.5, 0.8, 1.2, 0.7, 0.4, 1.1, 1.7, 0.5}}
\def\names{{"dots","horizontal lines","vertical lines","grid","north east lines","north west lines","bricks", "crosshatch"}}%
\def\width{1}
\coordinate (L) at (\width,0);
\foreach \i in {1,2,3}
{ \pgfmathsetmacro{\b}{\zthick[\i]};
\draw [pattern=\pgfmathparse{\names[\i]}\pgfmathresult ]
(L) ++(-\width,0) rectangle ++(\width,-\b) coordinate (L); }
\end{tikzpicture}
\end{document}
I understand this task can be achieved writing explicitly for each block, but I would like to know if there is any way to make it work with loops.


