# Drawing particles in a box

I want to draw a figure, somewhat like this: Maybe with the left box labeled State 1, and the right box labeled State 2. I searched on how to draw rectangles as a start, but I could not make much progress from there.

Here is what I have right now:

\hspace{4.75cm} \textbf{State 1} \hspace{1.5cm} \textbf{State 2} \\
\begin{center}
\begin{tikzpicture}[domain=0:2]
\draw(0,5)--(0,3)--(2,3)--(2,5);
\draw(-3, 5)--(-3, 3)--(-1, 3)--(-1, 5);
\draw (0.5, 3.5) circle(0.2cm);
\draw (1.5, 4.5) circle(0.2cm);
\draw (-2.5, 3.5) circle(0.2cm);
\draw (-1.5, 4.5) circle(0.2cm);
\end{tikzpicture}
\end{center}


It produces the following: ## 1 Answer

You can place text at any position using nodes, which can come with shapes like ellipses.

\documentclass[tikz, margin=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[egg/.style={ellipse,thick,draw,inner ysep=1.5pt}]
\draw[very thick] (0,0) rectangle (4,2) (2,2) -- (2,0);
\draw (0.7,1.5) node[egg](A) {A} (1.3,0.5) node[egg](B) {B}
(2.7,1.5) node[egg](C) {C} (3.3,0.5) node[egg](D) {D}
(1,2.5) node[font=\bfseries]{State 1} (3,2.5) node[font=\bfseries]{State 2};
\end{tikzpicture}
\begin{tikzpicture}[egg/.style={ellipse,thick,draw,inner ysep=1.5pt}]
\draw[very thick] (0,2) |- (4,0) -- (4,2) (2,2) -- (2,0);
\draw (0.7,1.5) node[egg](A) {A} (1.3,0.5) node[egg](B) {B}
(2.7,1.5) node[egg](C) {C} (3.3,0.5) node[egg](D) {D}
(1,2.5) node[font=\bfseries]{State 1} (3,2.5) node[font=\bfseries]{State 2};
\end{tikzpicture}
\end{document} • Thanks, this works. Is there any good way to label the diagrams, other than using the \hspace method that I included in my original post? – Ekesh Sep 9 '18 at 17:57
• @Ekesh Of course, with nodes. Do you want the top line removed like in your example? – user121799 Sep 9 '18 at 17:58
• No, I want the top line there please. I am just trying to get labels more efficiently – Ekesh Sep 9 '18 at 18:03
• @Ekesh I just added both options. BTW, your code is nice, but it would be even nicer if it started with \documenclass and ended with \end{document}, such that other can just copy the full thing and compile it. – user121799 Sep 9 '18 at 18:05