I'm looking for a way to cross wires in Circuitikz.
1B in the above picture shows what I'm after.
Example has been taken from the circuitikz
manual.
\documentclass[tikz]{standalone}
\usepackage{circuitikz}
\tikzset{
declare function={% in case of CVS which switches the arguments of atan2
atan3(\a,\b)=ifthenelse(atan2(0,1)==90, atan2(\a,\b), atan2(\b,\a));
},
kinky cross radius/.initial=+.125cm,
@kinky cross/.initial=+,
kinky crosses/.is choice,
kinky crosses/left/.style={@kinky cross=-},
kinky crosses/right/.style={@kinky cross=+},
kinky cross/.style args={(#1)--(#2)}{
to path={
let \p{@kc@}=($(\tikztotarget)-(\tikztostart)$),
\n{@kc@}={atan3(\p{@kc@})+180} in
-- ($(intersection of \tikztostart--{\tikztotarget} and #1--#2)!%
\pgfkeysvalueof{/tikz/kinky cross radius}!(\tikztostart)$)
arc [ radius =\pgfkeysvalueof{/tikz/kinky cross radius},
start angle=\n{@kc@},
delta angle=\pgfkeysvalueof{/tikz/@kinky cross}180 ]
-- (\tikztotarget)
}
}
}
\begin{document}
\begin{circuitikz}[thick, line cap=rect, nodes={line cap=butt}]
\draw [x=+.8cm, y=+1.1cm]
(2,4.5) -- (0,4.5)
to [Tpmos, n=p1] (0,3 ) coordinate (a-a)
to [Tnmos, n=n1] (0,1.5)
to [Tnmos, n=n2] (0,0 ) node[ground] {}
(2,4.5) to [Tpmos, n=p2] (2,3 ) coordinate (a-b)
to [short, -*] (a-a)
(p1.G) to [kinky cross=(a-a)--(a-b), kinky crosses=left] (n1.G)
to [short, *-o] ([shift=(right:3)]n1.G) coordinate (b-b)
([shift=(right:2)] n2.G) node[circ] {}
-- (n2.G-|p2.G)
to [kinky cross=(n1.G)--(b-b)] (p2.G)
(n2.G) to [short, -o] ([shift=(right:3)] n2.G)
(a-a) to [short, -o] (-1,3 );
\end{circuitikz}
\end{document}
A to[crossing]
connection works too. This is less adaptive than Qrrbrbirlbel's answer, however: compare the result of the two snippets below.
\begin{circuitikz}
\draw (0,0)
coordinate(A)
to[short] ++(2,-1) % \
coordinate(B);
\draw (0,-1)
to[kinky cross=(A)--(B), kinky crosses=left] ++(1,1); % /
\end{circuitikz}
versus
\begin{circuitikz}
\draw (0,0)
coordinate(A)
to[short] ++(2,-1) % \
coordinate(B);
\draw (0,-1)
to[crossing] ++(1,1); % /
\end{circuitikz}
You'll see that by using the in-built to[crossing]
, you miss the actual crossing. Also, that kink is smaller than Qrrbrbirlbel's kink, which is perhaps less desirable too.