我是新手circuitikz
并且对 TikZ 还不太熟悉,有一个看似简单的问题。我的电阻上的标签位于相反的两侧,我找不到任何原因。
\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{tikzpicture}[node distance = 0.5cm, auto, font=\tiny, inner sep =0.8mm,american voltages]
\ctikzset {label/align = straight }
%PSU
\draw[dashed](0.5,-3.5)rectangle(3.5,2.5);
\node at (2,2.7) (PSU_l){PSU};
\draw (2,0) to[V=$V_{\mathrm{DS}}$,*-*] (2,2);
\draw (2,-3) to[V=$V_{\mathrm{GS}}$,*-*] (2,-1);
\draw (2,-1) to (4,-1) to (4,0) to (2,0);
%Load resistors
\draw (2,2) to (4,2);
\draw (4,2)to[R=$R_{\mathrm{L1}}$,*-*] (4,0);
\draw (2,-3) to (4,-3);
\draw(4,-3)to[R=$R_{\mathrm{L2}}$,*-*] (4,-1);
\end{tikzpicture}
\end{document}
我大概可以(半)手动放置标签(因为我不知道如何放置相对于路径的节点,所以我现在必须完全手动放置它们)但我确信应该有一种方法可以说明在电阻的哪一侧(或其他线)放置标签。
答案1
正如评论中提到的,您会得到不同的位置,因为路径使用了不同的方向:第一个组件位于向下的路径上,而第二个组件位于向上的路径上。
circuitikz
使用路径的方向来放置标签;默认情况下,对于向下的路径,标签放置在右侧;对于从左到右的路径,标签放置在上方;对于向上的路径,标签放置在左侧;对于从右到左的路径,标签放置在下方。可以使用l^
,l_
修饰符更改默认放置位置(请参阅下面的第二个代码)。
为了获得一致的结果,您可以简单地使用相同方向的路径绘制组件,因此对于第二个组件,而不是
\draw(4,-3)to[R=$R_{\mathrm{L2}}$,*-*] (4,-1);
您可以使用
\draw(4,-1)to[R=$R_{\mathrm{L2}}$,*-*] (4,-3);
完整示例:
\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{tikzpicture}[node distance = 0.5cm, auto, font=\tiny, inner sep =0.8mm,american voltages]
\ctikzset {label/align = straight }
%PSU
\draw[dashed](0.5,-3.5)rectangle(3.5,2.5);
\node at (2,2.7) (PSU_l){PSU};
\draw (2,0) to[V=$V_{\mathrm{DS}}$,*-*] (2,2);
\draw (2,-3) to[V=$V_{\mathrm{GS}}$,*-*] (2,-1);
\draw (2,-1) to (4,-1) to (4,0) to (2,0);
%Load resistors
\draw (2,2) to (4,2);
\draw (4,2)to[R=$R_{\mathrm{L1}}$,*-*] (4,0);
\draw (2,-3) to (4,-3);
\draw(4,-1)to[R=$R_{\mathrm{L2}}$,*-*] (4,-3);
\end{tikzpicture}
\end{document}
另一种选择是沿任意方向绘制路径,然后使用l^=
或l_=
语法将标签放在适当的位置:
\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{tikzpicture}[node distance = 0.5cm, auto, font=\tiny, inner sep =0.8mm,american voltages]
\ctikzset {label/align = straight }
%PSU
\draw[dashed](0.5,-3.5)rectangle(3.5,2.5);
\node at (2,2.7) (PSU_l){PSU};
\draw (2,0) to[V=$V_{\mathrm{DS}}$,*-*] (2,2);
\draw (2,-3) to[V=$V_{\mathrm{GS}}$,*-*] (2,-1);
\draw (2,-1) to (4,-1) to (4,0) to (2,0);
%Load resistors
\draw (2,2) to (4,2);
\draw (4,2)to[R=$R_{\mathrm{L1}}$,*-*] (4,0);
\draw (2,-3) to (4,-3);
\draw(4,-3)to[R,l_=$R_{\mathrm{L2}}$,*-*] (4,-1);
\end{tikzpicture}
\end{document}
答案2
PSTricks 解决方案:
\documentclass{article}
\usepackage{pst-circ}
\begin{document}
\begin{pspicture}(7.25,10.4)
\pnodes{P}(0,0)(0,0)(0,10)(5,10)(2.5,1)(2.5,4.5)(6,4.5)(6,1)(2.5,5.5)(2.5,9)(6,9)(6,5.5)
\psframe[linestyle = dashed](P1)(P3)
\pcline[linestyle = none, offset = 9pt](P2)(P3)
\ncput{\textsc{psu}}
\psset{arrows = *-*, dipolestyle = zigzag, labelInside = 2, labeloffset = 1}
\Ucc(P4)(P5){$V_{\textsc{gs}}$}
\wire(P5)(P6)
\resistor(P6)(P7){$R_{\textsc{l}2}$}
\wire(P7)(P4)
\Ucc(P8)(P9){$V_{\textsc{ds}}$}
\wire(P9)(P10)
\resistor(P10)(P11){$R_{\textsc{l}1}$}
\wire(P11)(P8)
\end{pspicture}
\end{document}