是否有可能($(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}