Consider the following figure:
\begin{tikzpicture}[
selected/.style={circle, draw=black, fill=yellow!60, very thick},
unselected/.style={circle, draw=black, very thick}
]
\node[selected] (0) at (0, 0) {$x_1$};
\node[unselected] (1) at (1.5, 0) {$\bar x_1$};
\node[selected] (2) at (4, 0) {$x_2$};
\node[unselected] (3) at (5.5, 0) {$\bar x_2$};
\node[unselected] (4) at (8, 0) {$x_3$};
\node[selected] (5) at (9.5, 0) {$\bar x_3$};
\node[unselected] (6) at (-1.5, -1.5) {$x_1$};
\node[selected] (7) at (-1.5, -3) {$\bar x_2$};
\node[selected] (8) at (-1.5, -4.5) {$\bar x_3$};
\node[selected] (9) at (0, -6) {$\bar x_1$};
\node[unselected] (10) at (1.5, -6) {$x_2$};
\node[selected] (11) at (3, -6) {$\bar x_3$};
\draw[-] (0) -- (1)
(2) -- (3)
(4) -- (5);
\draw[-] (6) -- (7)
(7) -- (8)
(6) to [bend right=45] (8);
\draw[-] (9) -- (10)
(10) -- (11)
(9) to [bend right=45] (11);
\draw[-] (6) -- (0)
(7) -- (3)
(8) -- (5)
(9) -- (1)
(10) -- (2)
(11) -- (5);
\end{tikzpicture}
Now, I try using a foreach loop and some math:
\begin{tikzpicture}[
selected/.style={circle, draw=black, fill=yellow!60, very thick},
unselected/.style={circle, draw=black, very thick}
]
\node[selected] (0) at (0, 0) {$x_1$};
\node[unselected] (1) at (1.5, 0) {$\bar x_1$};
\node[selected] (2) at (4, 0) {$x_2$};
\node[unselected] (3) at (5.5, 0) {$\bar x_2$};
\node[unselected] (4) at (8, 0) {$x_3$};
\node[selected] (5) at (9.5, 0) {$\bar x_3$};
\node[unselected] (6) at (-1.5, -1.5) {$x_1$};
\node[selected] (7) at (-1.5, -3) {$\bar x_2$};
\node[selected] (8) at (-1.5, -4.5) {$\bar x_3$};
\node[selected] (9) at (0, -6) {$\bar x_1$};
\node[unselected] (10) at (1.5, -6) {$x_2$};
\node[selected] (11) at (3, -6) {$\bar x_3$};
\draw[-] (0) -- (1)
(2) -- (3)
(4) -- (5);
\foreach \x in {0,...,1}{
\pgfmathsetmacro\a{6+3*\x}
\pgfmathsetmacro\b{7+3*\x}
\pgfmathsetmacro\c{8+3*\x}
\draw[-] (\a) -- (\b)
(\b) -- (\c)
(\a) to [bend right=45] (\c);
}
\draw[-] (6) -- (0)
(7) -- (3)
(8) -- (5)
(9) -- (1)
(10) -- (2)
(11) -- (5);
\end{tikzpicture}
Why do the lines in the latter plot all connect to the right-most corner of the nodes rather than how they connected beforehand?
And help would be most appreciated!



\pgfmathtruncatemacroinstead of\pgfmathsetmacrobecause otherwise pgf will come up with numbers like2.0, where0is interpreted as node anchor. – Nov 09 '21 at 05:33Secondly, I cannot close questions. I can only suggest to close them. Other users then have to vote if the closure is justified or not. They can contradict by voting to “leave it open”.
– Roland Nov 09 '21 at 22:54