我该如何改进此代码?我想知道是否有更好的方法。另外,是否有某种方法可以更改电路图的尺寸而无需手动更改数字?
\documentclass{article}
\usepackage{circuitikz}
\usepackage{amsmath}
\begin{document}
\begin{center}
\begin{circuitikz}
\coordinate (C) at (3.9,1.5);
\coordinate (R) at (4,5);
\coordinate (A) at (6,5);
\coordinate (B) at (6,1.45);
\coordinate (D) at (-1, 3.5);
\draw (0,0) to[vsourcesin] (0,7);
\draw (0,7) to (5,7);
\draw[stealth-] (5,6) to (6,6);
\node at (A) {$V_r$};
\draw (6,6) to (6,5.4);
\draw (6,4) to (6,4.6);
\draw[stealth-] (5,4) to (6,4);
\draw (5,7) to[generic] (5,3);
\node at (R) {$10K$};
\draw (5,3) to[capacitor] (5,0);
\node at (C) {$0.1\mu F$};
\draw[stealth-] (5,2.2) to (6,2.2);
\draw (6,2.2) to (6,1.7);
\node at (B) {$V_c$};
\draw (6,1.25) to (6,0.8);
\draw[stealth-] (5,0.8) to (6, 0.8);
\draw (5,0) to (0,0);
\node at (D) {$V_{\textrm{in}}$};
\draw[stealth-] (0,2.45) to (-1.1,2.45);
\draw[stealth-] (0,4.5) to (-1.1,4.5);
\draw (-1.1, 4.5) to (-1.1, 3.82);
\draw(-1.1, 3.23) to (-1.1, 2.45);
\end{circuitikz}
\end{center}
\end{document}
此代码产生:
原始图像
答案1
您的电路方案有点不寻常...下面的 MWE 是两种方式的代码,如何绘制它:
- 通常(标准化)方式
- 随心所欲
\documentclass[margin=3mm]{standalone}
\usepackage[siunitx]{circuitikz}
\usetikzlibrary{ext.paths.ortho}
\begin{document}
\begin{circuitikz}[european]
\ctikzset{bipoles/capacitor/height=0.5,
bipoles/capacitor/width/.initial=.1,
resistors/scale=0.8,
voltage/bump b=20pt,voltage/european label distance=1pt
}
%
\draw (0,0) to[vsourcesin, v=$V_\mathrm{in}$, voltage/european label distance=1.3pt] ++(0,4)
to[short] ++ (3,0)
to[R, a=10<\kilo\ohm>, v^=$V_f$] ++(0,-2) % , a=10<\kilo\ohm>\)
to[C, a=0.1<\micro\farad>,v^=$V_c$] ++(0,-2) % , a=0,1<\micri\farad>\)
to[short, -.] ++ (-3,0);
\end{circuitikz}
\quad and \quad
\begin{circuitikz}[european,
lbl/.style = {midway, fill=white, inner sep=2pt}
]
\ctikzset{bipoles/capacitor/height=0.5,
bipoles/capacitor/width/.initial=.1
}
%
\draw (0,0) to[vsourcesin, name=V] ++(0,4)
to[short] ++ (3,0)
to[R, a=10<\kilo\ohm>,name=R] ++(0,-2)
to[C, a=0.1<\micro\farad>, name=C] ++(0,-2)
to[short, -.] ++ (-3,0);
\draw[<->] ([yshift=2mm] V.east) -|- [distance=-9mm] ([yshift=-2mm] V.west) node[lbl] {$V_{\mathrm{in}}$};
\draw[<->] ([yshift=2mm] R.west) -|- [distance= 9mm] ([yshift=-2mm] R.east) node[lbl] {$V_f$};
\draw[<->] ([yshift=4mm] C.west) -|- [distance= 9mm] ([yshift=-4mm] C.east) node[lbl] {$V_c$};
\end{circuitikz}
\end{document}
附录:
对于使用 Overleaf 且尚未安装 ext.paths.ortho 包的用户来说,不使用此库的“经典”解决方案是:
\documentclass[margin=3mm]{standalone}
\usepackage[siunitx]{circuitikz}
\usetikzlibrary{arrows.meta,
ext.paths.ortho}
\begin{document}
\ctikzset{bipoles/capacitor/height=0.5,
bipoles/capacitor/width/.initial=.1,
resistors/scale=0.8,
voltage/bump b=20pt,voltage/european label distance=1pt
}
\begin{circuitikz}[european,
> = Straight Barb,
lbl/.style = {midway, fill=white, inner sep=2pt, pos=0.25}
]
\ctikzset{bipoles/capacitor/height=0.5,
bipoles/capacitor/width/.initial=.1
}
%
\draw (0,0) to[vsourcesin, name=V] ++(0,4)
to[short] ++ (3,0)
to[R, a=10<\kilo\ohm>,name=R] ++(0,-2)
to[C, a=0.1<\micro\farad>, name=C] ++(0,-2)
to[short, -.] ++ (-3,0);
\draw[<->] ([yshift=2mm] V.east) -- ++ (-9mm,0) |- ([yshift=-2mm] V.west) node[lbl] {$V_{\mathrm{in}}$};
\draw[<->] ([yshift=2mm] R.west) -- ++ (+9mm,0) |- ([yshift=-2mm] R.east) node[lbl] {$V_f$};
\draw[<->] ([yshift=4mm] C.west) -- ++ (+9mm,0) |- ([yshift=-4mm] C.east) node[lbl] {$V_c$};
\end{circuitikz}
\end{document}