我是新來的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}