Why does the --cycle
command doesn’t work in a circuit drawn with the TikZ library circuits.ee.IEC
? The problem with manually draw the last connection is that the ends are not joined.
I made the lines very thick to demonstrate the problem of not joining …
Is it possible to fix this or at least join the path manually?
Code
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\begin{document}
\begin{tikzpicture}[circuit ee IEC, line width=5pt]
\draw (0,0) -- ++(0,2) node [above] {without objects}%
-- ++(4,0) -- ++(0,-2)%
--cycle node [below] {works};
\draw (0,-4.5) to[voltage source] ++(0,2) node [above] {with -\/-cycle}%
-- ++(4,0) to[resistor] ++(0,-2)%
--cycle node [below] {no connection};
\draw (0,-9) to[voltage source] ++(0,2) node [above] {manually}%
-- ++(4,0) to[resistor] ++(0,-2)%
-- ++(-4,0) node [below] {not joined};
\end{tikzpicture}
\end{document}
Best Answer
The manual on the
--cycle
operation:So apparently there is a move-to operation when the voltage source and resistor are added (which makes perfect sense) therefore the cycle is actually made, only it just draws a line back to the end of the resistor in this case over the line that's already there.
I can't think of any way to fix this behaviour, a move has to be made in the pgf path in order to 'skip' the symbol for the resistor (and voltage source). We can perform a little trick to get a proper join when adding the line manually though. Basically what we do is just draw a short line up over the one already there, this will create a smooth join on top of what's already there.
And the resulting document: