在我的电路中,我添加了矩形来表示组成它的不同块。我希望每个块的名称出现在矩形的底部并位于矩形的中心。目前,我被迫使用摸索得到的“真实”坐标来放置,但这不是一种非常干净的方式。我的各种测试只使文本出现在绘制的矩形的对角线上。
\documentclass[border=1mm]{standalone}
\usepackage[european, straightvoltages]{circuitikz}
\usetikzlibrary{babel}
\begin{document}
\begin{circuitikz}
\draw (0,0) node[en amp](aop1){AO1};
\draw (aop1.+)
to[short] ++(0,-2) node[ground](GND){};
\draw (aop1.-)
--++(0,1.5) coordinate (in-1)
--++(-2,0) node[npn, photo, anchor=E](photo){} ;
\draw (photo.C)
--++(-2,0) coordinate (pile)
to[battery2] (pile|-GND);
\draw (in-1)
to [vR, mirror] (in-1 -|aop1.out)
to[short] (aop1.out);
\draw (GND)
to[short] (GND-|pile);
%Tracé des blocs
\coordinate (rect1haut) at ($(pile)+(-0.5,0.5)$);
\coordinate (rect1bas) at ($(GND)+(-1,-1)$);
\draw [dashed] (rect1bas)
rectangle (rect1haut);
\path (-4,-3.6) node{Détecteur}
(-4,-4) node{d'obscurité};
\end{circuitikz}
\end{document}
谢谢您的帮助。
答案1
使用fit
矩形的库和节点:
\documentclass[border=1mm]{standalone}
\usepackage[european, straightvoltages]{circuitikz}
\usetikzlibrary{babel,
fit}
\begin{document}
\begin{circuitikz}
\draw (0,0) node[en amp](aop1){AO1};
\draw (aop1.+)
to[short] ++(0,-2) node[ground](GND){};
\draw (aop1.-)
--++(0,1.5) coordinate (in-1)
--++(-2,0) node[npn, photo, anchor=E](photo){} ;
\draw (photo.C)
--++(-2,0) coordinate (pile)
to[battery2] (pile|-GND);
\draw (in-1)
to [vR, mirror] (in-1 -|aop1.out)
to[short] (aop1.out);
\draw (GND)
to[short] (GND-|pile);
%Tracé des blocs
\node [draw, densely dashed, inner xsep=1.5em,
fit=(pile) (photo |- GND),
label={[align=center]below: Détecteur\\ d'obscurité}] {};
\end{circuitikz}
\end{document}
编辑:
通过改变坐标来修正虚线矩形的大小fit
,因此现在旧的坐标定义已被删除。
附录:
我认为你的方案有错误,因此(为了练习)我重写了你的代码,使其正确并且更简短一些,并且使得方案(在我看来)更漂亮:
\documentclass[border=1mm]{standalone}
\usepackage[european, straightvoltages]{circuitikz}
\usetikzlibrary{babel,
fit}
\begin{document}
\begin{circuitikz}
\draw (0,0) node[en amp] (ao1) {AO1}
(ao1.+) to[short] ++ (0,-2)
node[red, ground] (GND) {}
(ao1.-) |- ++ (-1,1.5) node[npn, photo, anchor=E] (photo) {}
(ao1.out) to [short] (ao1.out |- photo.E)
to [vR,invert] (photo.E -| ao1.-)
to [short] (ao1.-)
(photo.C) -- ++ (-2,0) coordinate (aux)
to[battery2,name=pile] (aux |- GND);
%Tracé des blocs
\node [draw, densely dashed, inner xsep=1.5em,
fit=(photo) (pile |- GND),
label={[align=center]below: Détecteur\\ d'obscurité}] {};
\end{circuitikz}
\end{document}
答案2
答案3
您可以将虚线绘制为具有虚线边框的节点并使用该label
选项。
%Tracé des blocs
\node[dashed,draw,minimum width=3cm,minimum height=6.5cm,
label={[align=center]below:Détecteur\\d'obscurité}]
at ($(pile)+(1,-2.9)$) {};
\documentclass[border=1mm]{standalone}
\usepackage[european, straightvoltages]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (0,0) node[en amp](aop1){AO1};
\draw (aop1.+)
to[short] ++(0,-2) node[ground](GND){};
\draw (aop1.-)
--++(0,1.5) coordinate (in-1)
--++(-2,0) node[npn, photo, anchor=E](photo){} ;
\draw (photo.C)
--++(-2,0) coordinate (pile)
to[battery2] (pile|-GND);
\draw (in-1)
to [vR, mirror] (in-1 -|aop1.out)
to[short] (aop1.out);
\draw (GND)
to[short] (GND-|pile);
%Tracé des blocs
\node[dashed,draw,minimum width=3cm,minimum height=6.5cm,
label={[align=center]below:Détecteur\\d'obscurité}]
at ($(pile)+(1,-2.9)$) {};
\end{circuitikz}
\end{document}