我circuitikz
经常使用电路图,其中许多电路图的底部都有某种电路元件,这使得电路图“不对称”或“不是完美的矩形”(如果我遗漏了一些技术术语,请原谅我)。从我之前发过的帖子,我了解了\frame
和\fbox
命令,它们对矩形图片很有效,但(在我看来)对这样的图则无效:
有没有办法解决这个问题,而无需对值进行硬编码?
上述代码:
\frame{
\begin{circuitikz}[european, voltage shift=0.5]
\draw (0,0) to [isource, l=$I_0$, v=$V_0$] (0,3)
to [short, -*, i=$I_0$] (2,3)
to [R=$R_1$, i>_=$i_1$] (2,0) -- (0,0);
\draw (2,3) -- (4,3)
to [R=$R_2$, i>_=$i_2$]
(4,0) to [short, -*] (2,0);
\end{circuitikz}
}
编辑我意识到水平方向也存在一些不对称现象,我没有在“我想要的”图中消除它,但我希望它也能得到修复。这可能吗?
答案1
这是为了展示我在评论中暗示的方法;请阅读文件中的评论。该fit
库非常有用,并在 Ti 中进行了解释钾Z 手册。此解决方案的重点是您可以决定主图像中的内容(您希望框与之对称)以及要忽略的内容。在我的第一个示例中,我将忽略主矩形外的所有内容;在第二个示例中,基本上,唯一被忽略的内容是$I=0$
顶部的标签。
这是整个代码;我将在下面发布仅取消注释红色或蓝色框的图像,以使其更清晰。
\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}[european, voltage shift=0.5]
% naming coordinate here
\draw (0,0) to [isource, l=$I_0$, v=$V_0$, name=sI0] (0,3) coordinate(top l)
to [short, -*, i=$I_0$] (2,3)
to [R=$R_1$, i>_=$i_1$] (2,0) -- (0,0) coordinate(bottom l);
\draw (2,3) -- (4,3) coordinate(top r)
to [R=$R_2$, i>_=$i_2$, name=R2]
(4,0) coordinate(bottom r) to [short, -*] (2,0);
%
% using fit, we find the box that we want to use as the part we want
% to use when pasting the "symmetric box" around the figure. The red
% thin one is just to show the basic box, the thick one is the resulting
% box
%
\node[draw, thin, dashed, red,
fit=(top l) (bottom l) (top r) (bottom r), inner sep=0pt](){};
\node[draw, red,
fit=(top l) (bottom l) (top r) (bottom r),
inner xsep=1cm, inner ysep=0.5cm](){};
%
% you can add other nodes to the fit thing too. For example, let's decide
% that the source and R2, with the labels, are to be considered for the
% symmetry (blue lines)
%
\node[draw, thin, dashed, blue,
fit=(top l) (bottom l) (top r) (bottom r) (sI0label) (R2label),
inner sep=0pt](){};
\node[draw, blue,
fit=(top l) (bottom l) (top r) (bottom r) (sI0label) (R2label),
inner sep=0.5cm](){};
\end{tikzpicture}
\end{document}
仅使用红色框:
只使用蓝色的:
答案2
简单的方法是用 tikz 绘制一个矩形,我将其添加到您的代码中:
\documentclass[border=2mm]{standalone}
\usepackage [EFvoltages]{circuitikz}
\begin{document}
\begin{circuitikz}[european, voltage shift=0.5]
\draw (0,0) to [isource, l=$I_0$, v=$V_0$] (0,3)
to [short, -*, i=$I_0$] (2,3)
to [R=$R_1$, i>_=$i_1$] (2,0) -- (0,0);
\draw (2,3) -- (4,3)
to [R=$R_2$, i>_=$i_2$] (4,0) to [short, -*] (2,0);
\draw[thick] (-1,-1) rectangle (5,4); % the frame
\end{circuitikz}
\end{document}