# Please suggest some tools to draw a diagram with blocks?

I want to draw this image using latex code. Please help me

• Welcome to TeX.SX! What have you tried so far? This is no do-it-for-me-service, so please add a minimal code example of your attempts to clarify the question. – TeXnician Sep 4 '17 at 12:53
• it seems that you like that some draw this image instead of you ... sorry, but site doesn't provide such a services. show us, what you try so far and we will help you where you will stuck in drawing. welcome to tex.se! – Zarko Sep 4 '17 at 12:55
• I agree with the above comments. I just want to add that you can use tikz and the basic commands are: 1) for rectangle:\draw (X1,Y1)rectangle(X2,Y2); where 1 and 2 are "diagonally opposite" corners if you want it dashed try: \draw[dashed]... 2) for circle the command is \draw[fill=black] (xcenter,yexnter) circle (0.3 cm) where 0.3 cm is the radious. 3)For line: \draw (x1,y1)--(x2,y2);Also you can use foreach command to avoid repeating same commands. More help after MWE. (Just added the comment so you can give a try... I think there are better options) – koleygr Sep 4 '17 at 13:15
• See tex.stackexchange.com/questions/205/… for suggestions – user36296 Sep 4 '17 at 13:16
• the point of a language like tikz is that it is text so you don't need a drawing tool just write it in whatever editor you use to write the rest of your document. If you want to draw that as an image in a drawing program, that's OK but then you don't need tikz, just save the image and include it into latex with \includegraphics – David Carlisle Sep 4 '17 at 13:32

I would do this by defining a "pic" for each "block" of dots. You can read all about these in section 18.2 of the tikz manual (version 3.0.1a). Using pics, the MWE below produces the following diagram:

The idea of the MWE, which should get you started, is to define a pic dotblock that takes two arguments: a label for the block and the number of dots. You use this pic in several different ways, including

\pic at (0,0) {dotblock={a,2}};
\draw (0,0) pic{dotblock={a,2}};


These two commands are, I believe, equivalent.

The block of dots is drawn centered vertically from the point where it is placed. The point of giving the dotblock a label is that it gives an easy way to draw edges between the dots in the blocks using their coordinates: the command

\draw(a2)--(b3);


draws a line from the second dot in "block a" to the third dot in "block b".

Here is a full MWE:

\documentclass{article}
\usepackage{tikz}

\tikzset{
pics/dotblock/.style args = {#1,#2}{% #1=label, #2=number of dots
code = {
evaluate=\adot as \y using 0.5-\adot+#2/2] in {1,...,#2} {
\node[circle, fill=black, radius=1mm] (#1\adot) at (0.5,\y) {};
}
\draw[blue](0,-#2/2) rectangle (1,#2/2);
}
}
}

\begin{document}

\begin{tikzpicture}
\pic at (0,0) {dotblock={a,2}};
\draw (2,0) pic{dotblock={b,3}};
\pic at (4,0) {dotblock={c,1}};
\draw[red, dashed, thin](-0.2,1.7) rectangle (5.2,-1.7);
\pic at (7,0) {dotblock={d,1}};

\draw(a1)--(b3)--(c1)--(d1);
\end{tikzpicture}
\end{document}


Given that the image in the OP has essentially three different types of repeating blocks I would actually define pics for each of them and then link them up. For example, the righthand block could be done with

 pics/twoBlock/.style args = {#1}{
code = {
\draw[dashed,green!80!black](0,0)--(6,0);
\draw(0,0) pic{dotblock={{#1}1,2}};
\draw(2,0) pic{dotblock={{#1}2,1}};
\draw[thin,red,dashed] (-0.2,1.2) rectangle (3.2,-1.2);
\draw(5,0) pic{dotblock={{#1}3,2}};
\draw[thin,red,dashed] (4.8,1.2) rectangle (6.2,-1.2);
}
}


so that \draw (7,0) pic{twoBlock={A}}; would produce

The twoBlock={A}, and the definition of twoBlock, means that the dots in this diagram are labelled as A11, A12, A21, A31 and A32. Notice that the green line is drawn first so that it is underneath the other objects in the picture.

• Thanks for help, how to make dotted lines between the blocks – new_born Sep 4 '17 at 16:06
• @new_born See the edit – Andrew Sep 5 '17 at 4:43