我正在寻找 Circuitikz 中的交叉电线的方法。
上图中的 1B 显示了我想要的内容。
答案1
例子取自circuitikz
手动的。
代码
\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}
输出
答案2
连接to[crossing]
也可以。不过,这不如 Qrrbrbirlbel 的答案那么自适应:比较下面两个代码片段的结果。
\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}
相对
\begin{circuitikz}
\draw (0,0)
coordinate(A)
to[short] ++(2,-1) % \
coordinate(B);
\draw (0,-1)
to[crossing] ++(1,1); % /
\end{circuitikz}
您会发现,使用内置的to[crossing]
,您会错过实际的交叉点。此外,该弯角比 Qrrbrbirlbel 的弯角小,这也许也不理想。