是否有可能($(M1.G)+(1.3,-0.2)$) node [below] {$M_1$}
使用諸如 之類的宏向給定位置 [ ]處的每個 MOS 晶體管元件添加標籤\lbl{1}
,這樣我就不必每次都添加具有不同編號的標籤,例如 M1、M2...
\begin{figure}[H]
\centering
\begin{circuitikz}[scale=1]
\ctikzset{tripoles/mos style/arrows}
\def\Ba{2,0.5}
\def\lbl{1.3,-0.2}
\draw
(\Ba) node [nmos] (M1) {} ($(M1.G)+(\lbl)$) node [below] {$M_1$}
(M1.S) node [ground] {}
($(\Ba)+(0,2)$) node [nmos] (M2) {}($(M2.G)+(1.3,-0.2)$) node [below] {$M_2$}
(M1.D) --(M2.S)
(M1.G) node[circ]{}node[left]{$V_B$}
(M2.G) node[circ]{}node[left]{$V_{in}$}
($(M1.D)+(0,0.25)$)--($(M1.D)+(1,0.25)$)node[circ]{$V_{out}$}
(M2.D) node [rground,yscale=-1] (vdd){} ;
\end{circuitikz}
\caption{\Common drain amplifier.}
\end{figure}
答案1
您可以定義例如縮寫
\newcommand\mynmos[1]{node [nmos] (M#1) {} ($(M#1.G)+(\lbl)$) node [below] {$M_{#1}$}}
並將其用作
\draw
(\Ba) \mynmos{1}
(M1.S) node [ground] {}
($(\Ba)+(0,2)$) \mynmos{2}
(完整代碼見下文)。
您也可以為標籤引入一個巨集;在這種情況下,您無法呼叫它,\lbl
因為您已經使用了該名稱。
\newcommand\lblnmos[1]{($(M#1.G)+(\lbl)$) node [below] {$M_{#1}$}}
...
\draw
(\Ba) node [nmos] (M1) {} \lblnmos{1}
(M1.S) node [ground] {}
($(\Ba)+(0,2)$) node [nmos] (M2) {} \lblnmos{2}
\documentclass{article}
\usepackage{circuitikz}
\begin{document}
\newcommand\mynmos[1]{node [nmos] (M#1) {} ($(M#1.G)+(\lbl)$) node [below] {$M_{#1}$}}
\begin{circuitikz}[scale=1]
\ctikzset{tripoles/mos style/arrows}
\def\Ba{2,0.5}
\def\lbl{1.3,-0.2}
\draw
(\Ba) \mynmos{1}
(M1.S) node [ground] {}
($(\Ba)+(0,2)$) \mynmos{2}
(M1.D) --(M2.S)
(M1.G) node[circ]{}node[left]{$V_B$}
(M2.G) node[circ]{}node[left]{$V_{in}$}
($(M1.D)+(0,0.25)$)--($(M1.D)+(1,0.25)$)node[circ]{$V_{out}$}
(M2.D) node [rground,yscale=-1] (vdd){} ;
\end{circuitikz}
\end{document}