CircuiTikZ 杆标尺寸

CircuiTikZ 杆标尺寸
\begin{circuitikz}
\draw (5,2) node[op amp] (opamp) {}
(0.5,2.5) to [short, o-, i^>=$I_{in}$] (2,2.5)
to [R, l=$R_{in}$] (opamp.-)
(0.5,2.5) node[above] {$V_{in}$}
(3.8,1) node [ground] {}
to [short] (opamp.+)
(3.8,3.5) to [R, l=$R_{load}$] (6.2,3.5)
(3.8,3.5) to [short, -*] (opamp.-)
(6.2,3.5) to [short, -*, i^>=$I_{load}$] (opamp.out)
(opamp.out) to [short, -o] (7, 2);
\end{circuitikz}

我有这段代码,我想知道如何自由改变加号和减号的大小,如果合理的话,更大,更小。

提前致谢。

答案1

我看不出如何修补该命令,因此如果您包含形状定义的副本op amp,则可以根据需要进行更改。下面,我提供了一个\SetScaleFactor{}宏来向您展示如何调整应用于-+的符号的比例因子opamp

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{circuitikz}

\makeatletter
\newcommand*{\@SetScaleFactor}{1}%
\newcommand*{\SetScaleFactor}[1]{\edef\@SetScaleFactor{#1}}%
\newcommand*{\ScaleSymb}[1]{\scriptsize\ \scalebox{\@SetScaleFactor}{#1}}%
\pgfdeclareshape{op amp}
    {
      \anchor{center}{\pgfpointorigin}
      \savedanchor\northwest{%
        \pgf@y= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
        \pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/height}\pgf@y
        \pgf@y=.5\pgf@y
        \pgf@x= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
        \pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/width}\pgf@x
        \pgf@x=.5\pgf@x
      }
      \anchor{south}{
        \northwest
        \pgf@y=-\pgf@y
      }
      \anchor{north}{
        \northwest
      }
      \savedanchor\left{%
        \pgf@y=0pt
      }
      \savedanchor\inOne{%
        \pgf@y= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
        \pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/height}\pgf@y
        \pgf@y=.5\pgf@y
        \pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/input height}\pgf@y
        \pgf@x= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
        \pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/width}\pgf@x
        \pgf@x=.5\pgf@x
      }   
      \anchor{-}{
        \inOne
      }
      \anchor{+}{
        \inOne
        \pgf@y=-\pgf@y
      }
      \savedanchor\up{%
        \pgf@y= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
        \pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/height}\pgf@y
        \pgf@y=.5\pgf@y
        \pgf@x= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
        \pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/width}\pgf@x
        \pgf@x=.5\pgf@x
            \pgf@circ@res@up = \pgf@y 
            \pgf@circ@res@right = -\pgf@x
            \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/up pos}}{
            \pgfpoint{
                \pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/port width}\pgf@circ@res@left}
                {\pgf@circ@res@up}}
            {\pgfpoint{.7\pgf@circ@res@right}{0pt}}
      }
      \anchor{up}{
        \up
      }
      \anchor{down}{
        \up
        \pgf@y=-\pgf@y
      }
      \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
      }
        \anchor{west}{
            \left
          }
          \anchor{east}{
            \left
            \pgf@x=-\pgf@x
          }  

      \backgroundpath{          
            \pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}   


            \northwest
            \pgf@circ@res@up = \pgf@y 
            \pgf@circ@res@down = -\pgf@y
            \pgf@circ@res@right = -\pgf@x
            \pgf@circ@res@left = \pgf@x

    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/input height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/port width}\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/input height}\pgf@circ@res@up}}
    \pgftext[left, at=\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/port width}\pgf@circ@res@left}{\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/input height}\pgf@circ@res@up}]{\ScaleSymb{$-$}}


    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/input height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/port width}\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/input height}\pgf@circ@res@down}}
    \pgftext[left, at=\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/port width}\pgf@circ@res@left}{\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/input height}\pgf@circ@res@down}]{\ScaleSymb{$+$}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{0pt}}

    \pgfusepath{draw}


    \pgfscope
        \pgfsetlinewidth{2\pgflinewidth}
        \pgftransformxshift{.7\pgf@circ@res@left}
        \pgf@circ@res@step=\pgf@circ@res@right
        \advance\pgf@circ@res@step by -\pgf@circ@res@left
        \pgf@circ@res@step=.7\pgf@circ@res@step

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfusepath{draw}
    \endpgfscope
      }
    }
\makeatother

\begin{document}
\begin{circuitikz}
    \draw (5,2) node[op amp, font=\tiny] (opamp) {}
    (0.5,2.5) to [short, o-, i^>=$I_{in}$] (2,2.5)
    to [R, l=$R_{in}$] (opamp.-)
    (0.5,2.5) node[above] {$V_{in}$}
    (3.8,1) node [ground] {}
    to [short] (opamp.+)
    (3.8,3.5) to [R, l=$R_{load}$] (6.2,3.5)
    (3.8,3.5) to [short, -*] (opamp.-)
    (6.2,3.5) to [short, -*, i^>=$I_{load}$] (opamp.out)
    (opamp.out) to [short, -o] (7, 2);

    \node at (5,0) {\textbackslash SetScaleFactor=1 (default)};
\end{circuitikz}
%
\SetScaleFactor{2.0}%
\begin{circuitikz}
    \draw (5,2) node[op amp, font=\tiny] (opamp) {}
    (0.5,2.5) to [short, o-, i^>=$I_{in}$] (2,2.5)
    to [R, l=$R_{in}$] (opamp.-)
    (0.5,2.5) node[above] {$V_{in}$}
    (3.8,1) node [ground] {}
    to [short] (opamp.+)
    (3.8,3.5) to [R, l=$R_{load}$] (6.2,3.5)
    (3.8,3.5) to [short, -*] (opamp.-)
    (6.2,3.5) to [short, -*, i^>=$I_{load}$] (opamp.out)
    (opamp.out) to [short, -o] (7, 2);

    \node at (5,0) {\textbackslash SetScaleFactor=2};
\end{circuitikz}
\end{document}

答案2

另一种方法是定义一个myopamp宏来删除默认op amp极性并使用缩放选项重新绘制它,如下所示。

\newcommand{\myopamp}[2] % #1 = name , #2 = scaling factor
{\draw[thick] (#1){};
 \filldraw[white] (#1.+) +(16pt,0) circle(3pt)  
                  (#1.-) +(16pt,0) circle(3pt);
 \draw[]          (#1.+) +(18pt,0) node(){\scalebox{#2}{$+$}}
                  (#1.-) +(18pt,0) node(){\scalebox{#2}{$-$}};
}

在此处输入图片描述

代码

\documentclass[border=5mm]{standalone}  
\usepackage[american,siunitx]{circuitikz}
%\usetikzlibrary{arrows,calc,positioning}

\newcommand{\myopamp}[2] % #1 = name , #2 = scaling factor
{\draw[thick] (#1){};
 \filldraw[white]  (#1.+) +(16pt,0) circle(3pt)  
                   (#1.-) +(16pt,0)circle(3pt);
 \draw[]           (#1.+) +(18pt,0) node(){\scalebox{#2}{$+$}}
                   (#1.-) +(18pt,0) node(){\scalebox{#2}{$-$}};
}

\begin{document}  

\begin{circuitikz}
\node at (5,5) {OP's result};
\draw (5,2) node[op amp] (opamp) {}
(0.5,2.5) to [short, o-, i^>=$I_{in}$] (2,2.5)
to [R, l=$R_{in}$] (opamp.-)
(0.5,2.5) node[above] {$V_{in}$}
(3.8,1) node [ground] {}
to [short] (opamp.+)
(3.8,3.5) to [R, l=$R_{load}$] (6.2,3.5)
(3.8,3.5) to [short, -*] (opamp.-)
(6.2,3.5) to [short, -*, i^>=$I_{load}$] (opamp.out)
(opamp.out) to [short, -o] (7, 2);
\end{circuitikz}



\begin{circuitikz}
\node at (5,5) {Proposed result};
\draw (5,2) node[op amp] (opamp) {};
\myopamp{opamp}{2}  %  add this command here
\draw (0.5,2.5) to [short, o-, i^>=$I_{in}$] (2,2.5)
to [R, l=$R_{in}$] (opamp.-)
(0.5,2.5) node[above] {$V_{in}$}
(3.8,1) node [ground] {}
to [short] (opamp.+)
(3.8,3.5) to [R, l=$R_{load}$] (6.2,3.5)
(3.8,3.5) to [short, -*] (opamp.-)
(6.2,3.5) to [short, -*, i^>=$I_{load}$] (opamp.out)
(opamp.out) to [short, -o] (7, 2);
\end{circuitikz}

\end{document}

相关内容