Circuitikz에서 매크로를 사용하여 요소에 레이블 지정

Circuitikz에서 매크로를 사용하여 요소에 레이블 지정

($(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}

관련 정보