1

Is there is any possibility of adding labels to each MOS transistor element at a given location [($(M1.G)+(1.3,-0.2)$) node [below] {$M_1$}] using macros like \lbl{1}, so that I don't have to add each time the label with different number like 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}

enter image description here

1 Answer 1

1

You can define e.g. the abbreviation

\newcommand\mynmos[1]{node [nmos] (M#1) {} ($(M#1.G)+(\lbl)$) node [below] {$M_{#1}$}}

and use it as

\draw           
  (\Ba) \mynmos{1}
  (M1.S) node [ground] {}
  ($(\Ba)+(0,2)$) \mynmos{2}

(see below for the complete code).

You can also introduce a macro just for the label; in this case you can't call it \lbl since you already use this name.

\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}

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .