我想要画一个图形,有点像这样:
也许左边的框标记为状态 1,右边的框标记为状态 2。我搜索了如何绘制矩形作为开始,但我没有取得太大进展。
以下是我现在拥有的:
\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}
它产生以下内容:
答案1
您可以使用 s 将文本放置在任何位置node
,s 可以带有像ellipse
s 这样的形状。
\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}