我的电路中有一个运算放大器,但我希望 + 极在上方,- 极在下方。我不知道该怎么做。(抱歉,我无法上传图片,这是我的第一篇帖子)
有人能帮助我吗?
\begin{center}
\begin{circuitikz} \draw
(0,0) node[op amp] (opamp) {}
;\end{circuitikz}
\end{center}
答案1
您可以使用yscale=-1
:
\documentclass{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (0,0) node[op amp] (opamp1) {}
(opamp1.+) node[left ] {$v_+$}
(opamp1.-) node[left ] {$v_-$};
\draw (3,0) node[op amp,yscale=-1] (opamp2) {}
(opamp2.+) node[left ] {$v_+$}
(opamp2.-) node[left ] {$v_-$};
\end{circuitikz}
\end{document}
答案2
为了消除任何疑惑(我知道在发现这个帖子后我肯定花了几个小时在 Google 上搜索):正如 Rmano 在评论在他的回答中,CircuiTikZ 现在使用选项原生支持反相/翻转运算放大器输入noinv input up
(这意味着“将非反相(即 +)输入绘制为上端子”),默认情况下关闭noinv input down
。事实上,使用 Rmano 答案中的代码得到的结果现在不如 CircuiTikZ 提供的结果理想!
答案比较(见下图):
-
\begin{circuitikz} \draw node[op amp, yscale=-1] (myopamp1) {$A$}; \end{circuitikz}
Rmano 的回答(他
makeatletter ... makeatother
在序言中):\begin{circuitikz} \draw node[op amp, noinv up] (myopamp1) {$A$}; \end{circuitikz}
自以下日期起,CircuiTikZ 中实现了本机选项:
\begin{circuitikz} \draw node[op amp, noinv input up] (myopamp1) {$A$}; \end{circuitikz}
您可以在 CircuiTikZ 1.3.0 手册第 3.22.2 节下找到有关通用放大器的更多信息(撰写本文时可在 CTAN 上获取)。
答案3
如果您只想切换+
和-
,则必须修改的定义op amp
。我所做的是添加一个选项noinv up
(以及相应的noinv down
,如果您想要重置样式),该选项可切换反转和无反转输入,让其他锚点保持原位。
此外,我还添加了锚点in up
,并in down
针对独立于新选项的“向上”和“向下”的输入添加了锚点。
代码在 和 之间\makeatletter
。\makeatother
代码需要最新版本的circuitikz
(你可以在 github 上找到它),原因难以理解;如果您想坚持使用您的版本,您可能需要复制您的定义op amp
并复制我所做的更改(在代码中标记在%%% RG:
标记之间)。它看起来很长而且很复杂,但基本上是对原始代码的最小更改......
PS:我准备了一个tikzcircuit github cod 的 pull request有这个以及更多的东西……
结果:
代码:
\documentclass[border=10pt]{standalone}
\usepackage[siunitx, oldvoltagedirection]{circuitikzgit}
% needs the latest version of circuitikz, see github (dunno why)
% \usepackage[siunitx]{circuitikz}
%
\makeatletter
%%% RG: added the option and the code to switch
\newif\ifpgf@circuit@oa@plusup\pgf@circuit@oa@plusupfalse
\pgfkeys{/tikz/noinv up/.add code={}{\pgf@circuit@oa@plusuptrue}}
\ctikzset{noinv up/.add code={}{\pgf@circuit@oa@plusuptrue}}
\pgfkeys{/tikz/noinv down/.add code={}{\pgf@circuit@oa@plusupfalse}}
\ctikzset{noinv down/.add code={}{\pgf@circuit@oa@plusupfalse}}
%%% RG stop
\pgfdeclareshape{op amp}
{
\anchor{center}{\pgfpointorigin}
\savedanchor\northwest{%
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/height}\pgf@circ@Rlen
\pgf@y=.5\pgf@y
\pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/width}\pgf@circ@Rlen
\pgf@x=.5\pgf@x
}
\anchor{south}{
\northwest
\pgf@y=-\pgf@y
\pgf@x=0pt
}
\anchor{north}{
\northwest
\pgf@x=0pt
}
\savedanchor\left{%
\pgf@y=0pt
}
\anchor{leftedge}
{\left
\pgf@x = \pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/port width}\pgf@x
}
%%% RG: added the fixed anchors
\savedanchor\inOneFixed{%
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/height}\pgf@circ@Rlen
\pgf@y=.5\pgf@y
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/input height}\pgf@y
\pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/width}\pgf@circ@Rlen
\pgf@x=.5\pgf@x
}
\anchor{in up}{
\inOneFixed
}
\anchor{in down}{
\inOneFixed
\pgf@y=-\pgf@y
}
%%% RG stop
\savedanchor\inOne{%
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/height}\pgf@circ@Rlen
\pgf@y=.5\pgf@y
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/input height}\pgf@y
\pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/width}\pgf@circ@Rlen
\pgf@x=.5\pgf@x
%%% RG: added the conditional flip
\ifpgf@circuit@oa@plusup\pgf@y=-\pgf@y\fi
%%% RG stop
}
\anchor{-}{
\inOne
}
\anchor{+}{
\inOne
\pgf@y=-\pgf@y
}
\savedanchor\up{%
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/height}\pgf@circ@Rlen
\pgf@y=.5\pgf@y
\pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/width}\pgf@circ@Rlen
\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}}
%%% RG: added the conditional for printing labels + and -
\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}]{\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/font} \ifpgf@circuit@oa@plusup$+$\else$-$\fi}
%%% RG stop
\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}}
%%% RG: added the conditional for printing labels + and -
\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}]{\pgfkeysvalueof{/tikz/circuitikz/tripoles/op amp/font} \ifpgf@circuit@oa@plusup$-$\else$+$\fi}
%%% RG stop
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
\pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{0pt}}
\pgfsetrectcap
\pgfusepath{draw}
\pgfscope
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/tripoles/thickness}\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}}
\pgfpathclose
\pgfusepath{draw}
\endpgfscope
}
}
\makeatother
\def\coord(#1){coordinate(#1)}
\def\coord(#1){node[circle, red, draw, inner sep=1pt,pin={[red, overlay, inner sep=0.5pt, font=\tiny, pin distance=0.1cm, pin edge={red, overlay,}]75:#1}](#1){}}
\def\coordd(#1){node[circle, red, draw, inner sep=1pt,pin={[red, overlay, inner sep=0.5pt, font=\tiny, pin distance=0.1cm, pin edge={red, overlay,}]-145:#1}](#1){}}
\ctikzset{tripoles/mos style/arrows, bipoles/thickness=1, }
\begin{document}
\begin{circuitikz}[ american, ]
%
\draw[cyan, dotted] (-2,-2) grid (2,5);
\node at (0,0) [op amp](OA1){};
\node at (OA1.up) [vcc]{};
\node at (OA1.down) [vee]{};
\foreach \a in {+,-,up,down,out} \path (OA1.\a) \coord(\a);
\foreach \a in {in up, in down} \path (OA1.\a) \coordd(\a);
\node at (0,3) [op amp, noinv up](OA2){};
\node at (OA2.up) [vcc]{};
\node at (OA2.down) [vee]{};
\foreach \a in {+,-,up,down,out} \path (OA2.\a) \coord(\a);
\foreach \a in {in up, in down} \path (OA2.\a) \coordd(\a);
\end{circuitikz}
\end{document}