
円の中の点を数値(1、2、3など)に置き換える方法を考えています
この置き換えを実行するために編集する必要があるコード行を特定するのにご協力ください。
前もって感謝します!
mwe (h/t pecusse)
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit}
\begin{document}
\begin{tikzpicture}
%put some nodes on the left
\foreach \x in {1,2,3}{
\node[fill,circle,inner sep=2pt] (d\x) at (0,\x) {};
}
\node[fit=(d1) (d2) (d3),ellipse,draw,minimum width=1cm] {};
%put some nodes on the center
\foreach \x[count=\xi] in {0.5,1.5,...,4}{
\node[fill,circle,inner sep=2pt] (r\xi) at (2,\x) {};
}
\node[fit=(r1) (r2) (r3) (r4),ellipse,draw,minimum width=1.5cm] {};
%put some nodes on the right
\foreach \x[count=\xi] in {0.75,1.5,...,3}{
\node[fill,circle,inner sep=2pt] (c\xi) at (4,\x) {};
}
\node[fit=(c1) (c2) (c3) (c4) ,ellipse,draw,minimum width=1.5cm] {};
\draw[-latex] (d1) -- (r2);
\draw[-latex] (d2) -- (r2);
\draw[-latex] (d3) -- (r4);
\draw[-latex] (r1) -- (c2);
\draw[-latex] (r2) -- (c3);
\draw[-latex] (d3) -- (r4);
\end{tikzpicture}
\end{document}
答え1
どの数字をどこに配置すればよいかはわかりませんが、一般的には、ノードの内容は中括弧で囲む必要があります: \node[options] (name) at (0,0) {
... };
。
\foreach
この例では、マクロ に格納されているループからの数値をノードに配置する必要があります\x
。ノードは黒く塗りつぶされているため、内部のテキストは表示されません。したがって、たとえば を使用して塗りつぶしの色を変更することをお勧めします。fill=lightgray
次のように記述できます\node[fill=lightgray,circle,inner sep=2pt] (d\x) at (0,\x) {\x};
。
3 セットすべてのノードに対してこれを行うと、ノードの内容の長さが異なり、したがって円のサイズも異なることがわかります。たとえば、一部のノードには 1 桁の数字しか含まれず、他のノードには 3 桁と小数点のドットが含まれます。minimum width=2.5em
すべてのノードを同じサイズにするには、ノードにオプション (または同様のオプション) を追加する必要があります。
最後に、サイズが大きくなるとノードが重なる可能性があるため、水平距離をそのままに垂直距離を増やすオプションをy=1.25cm
全体に対して設定できます。tikzpicture
すべてをまとめると次のようになります。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit}
\begin{document}
\begin{tikzpicture}[y=1.25cm]
%put some nodes on the left
\foreach \x in {1,2,3}{
\node[fill=lightgray,circle,inner sep=2pt,minimum width=2.5em] (d\x) at (0,\x) {\x};
}
\node[fit=(d1) (d2) (d3),ellipse,draw,minimum width=1cm] {};
%put some nodes on the center
\foreach \x[count=\xi] in {0.5,1.5,...,3.5}{
\node[fill=lightgray,circle,inner sep=2pt,minimum width=2.5em] (r\xi) at (2,\x) {\x};
}
\node[fit=(r1) (r2) (r3) (r4),ellipse,draw,minimum width=1.5cm] {};
%put some nodes on the right
\foreach \x[count=\xi] in {0.75,1.5,...,3}{
\node[fill=lightgray,circle,inner sep=2pt,minimum width=2.5em] (c\xi) at (4,\x) {\x};
}
\node[fit=(c1) (c2) (c3) (c4),ellipse,draw,minimum width=1.5cm] {};
\draw[-latex] (d1) -- (r2);
\draw[-latex] (d2) -- (r2);
\draw[-latex] (d3) -- (r4);
\draw[-latex] (r1) -- (c2);
\draw[-latex] (r2) -- (c3);
\draw[-latex] (d3) -- (r4);
\end{tikzpicture}
\end{document}
数字の背景が必要ない場合は、ノードのオプションをすべて削除することができます (また、 を設定する必要はありませんy=1.25cm
)。コメントで提供された画像に似た色を追加したい場合もあるため、左側の楕円と矢印の 1 つに色を追加しました。
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit}
\begin{document}
\begin{tikzpicture}
%put some nodes on the left
\foreach \x in {1,2,3}{
\node (d\x) at (0,\x) {\x};
}
\node[fit=(d1) (d2) (d3),ellipse,draw=blue,minimum width=1cm] {};
%put some nodes on the center
\foreach \x[count=\xi] in {0.5,1.5,...,3.5}{
\node (r\xi) at (2,\x) {\x};
}
\node[fit=(r1) (r2) (r3) (r4),ellipse,draw,minimum width=1.5cm] {};
%put some nodes on the right
\foreach \x[count=\xi] in {0.75,1.5,...,3}{
\node (c\xi) at (4,\x) {\x};
}
\node[fit=(c1) (c2) (c3) (c4),ellipse,draw,minimum width=1.5cm] {};
\draw[-latex,orange] (d1) -- (r2);
\draw[-latex] (d2) -- (r2);
\draw[-latex] (d3) -- (r4);
\draw[-latex] (r1) -- (c2);
\draw[-latex] (r2) -- (c3);
\draw[-latex] (d3) -- (r4);
\end{tikzpicture}
\end{document}