Tikz snake path has whitespace before/after node (MWE)
You have to handle decoration with care. I do not exactly know why this happens, but obviously, it is because you put multiple segments into one single \draw
command.
You should write one separate \draw
for every line segment. Or, to make it similar to your original version, you could use the following code:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\tikzset{
enclosed/.style={draw, circle, inner sep=0pt, minimum size=.15cm, fill=black},
enclosedM/.style={enclosed, fill=red}
}
\node[enclosed, label={left: $x$}] (x) at (0,2) {};
\node[enclosed, label={right: $y$}] (y) at (4,2) {};
\node[enclosed] (w) at (2,0) {};
\node[enclosed] (v) at (2,4) {};
\node[enclosedM, label={above: $z$}] (z) at (2,1) {};
\node[enclosedM, label={below: $t$}] (t) at (2,3) {};
\foreach\x in {
(x) -- (v),
(v) -- (y),
(x) -- (w),
(w) -- (y),
(x) -- (t),
(v) -- (t),
(y) -- (t),
(x) -- (z),
(w) -- (z),
(z) -- (y)
}
\draw[decorate,decoration={snake,amplitude=.2mm}] \x;
\end{tikzpicture}
\end{document}
Two comments (not a real answer): tikzstyle
is deprecated and if you draw the lines one by one there is no issue. (I have not checked if the problem is due to tikzstyle
.) UPDATE: compactified the code and a big thanks to @Zarko for catching the square brackets!
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\tikzset{Snake/.style={decorate,decoration={snake,amplitude=.2mm}},
enclosed/.style={draw, circle, inner sep=0pt, minimum size=.15cm,
fill=black},
enclosedM/.style={draw, circle, inner sep=0pt, minimum size=.15cm,
fill=red}}
\node[enclosed, label={left:$x$}] (x) at (0,2) {};
\node[enclosed, label={right:$y$}] (y) at (4,2) {};
\node[enclosed] (w) at (2,0) {};
\node[enclosed] (v) at (2,4) {};
\node[enclosedM, label={above:$z$}] (z) at (2,1) {};
\node[enclosedM, label={below:$t$}] (t) at (2,3) {};
\foreach \X in {x,y,v} \draw[Snake] (t) -- (\X);
\foreach \X in {x,y,w} \draw[Snake] (z) -- (\X);
\foreach \X in {x,y}{\foreach \V in {v,w} \draw[Snake] (\V) -- (\X);}
\end{tikzpicture}
\end{document}