我已经编写了以下电路:
\documentclass{article}
\usepackage[american]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw
(0,4) to [C,v^=\(v_c\),*-*] (0,1)
to [short] (0,0)
to [ospst=\mbox{t=0s}] (6,0)
to [battery,v_=45V] (6,5)
to [short] (5,5)
to [open,*-*] (3,5)
to [R=\parbox{1cm}{\(R_3\\5.6k\Omega\)}] (0,5)
to [short] (0,4)
to [short] (-6,4)
to [C,l_=\parbox{1cm}{\(C_1\\4.7\mu F\)}] (-6,1)
to [short] (0,1)
(-3,4)to [R,l_=\parbox{1cm}{\(R_4\\10k\Omega\)},*-*] (-3,1)
(3,6) to [short] (3,4)
to [R,l_=\parbox{1cm}{\(R_2\\39k\Omega\)}] (5,4)
to [short] (5,6)
to [R,l=\parbox{1cm}{\(R_1\\47k\Omega\)}] (3,6)
;
\end{circuitikz}
\end{document}
渲染后如下所示:
问题:
- 如何使元件参考标记 (R1) 和值 (47kΩ) 彼此水平对齐 (居中) 并与元件对齐?使用\定心,会产生编译错误,因为 \parbox 的内容是下标和希腊字母所需的方程式。
- 添加标签时(见下文)电容器和电池的电压会偏移,导致它们与元件重叠。如何解决此问题?
修改后的代码显示添加了标签(参见第一行和第四行之后\画命令):
\documentclass{article}
\usepackage[american]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw
(0,4) to [C,l_=\parbox{1cm}{\(C_2\\2.2\mu F\)},v^=\(v_c\),*-*] (0,1)
to [short] (0,0)
to [ospst=\mbox{t=0s}] (6,0)
to [battery,l=E,v_=45V] (6,5)
to [short] (5,5)
to [open,*-*] (3,5)
to [R=\parbox{1cm}{\(R_3\\5.6k\Omega\)}] (0,5)
to [short] (0,4)
to [short] (-6,4)
to [C,l_=\parbox{1cm}{\(C_1\\4.7\mu F\)}] (-6,1)
to [short] (0,1)
(-3,4)to [R,l_=\parbox{1cm}{\(R_4\\10k\Omega\)},*-*] (-3,1)
(3,6) to [short] (3,4)
to [R,l_=\parbox{1cm}{\(R_2\\39k\Omega\)}] (5,4)
to [short] (5,6)
to [R,l=\parbox{1cm}{\(R_1\\47k\Omega\)}] (3,6)
;
\end{circuitikz}
\end{document}
编译结果:
答案1
评论
\centering
只需在您的 es 内部使用即可parbox
。此外,我收到一个错误! LaTeX Error: There's no line here to end.
,这是因为换行符位于内联数学模式中。
执行
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage[american]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw
(0,4) to [C,l_=\parbox{1cm}{\centering\(C_2\)\\\(2.2\mu F\)},v^=\(v_c\),*-*] (0,1)
to [short] (0,0)
to [ospst=\mbox{t=0s}] (6,0)
to [battery,l=E,v_=45V] (6,5)
to [short] (5,5)
to [open,*-*] (3,5)
to [R=\parbox{1cm}{\centering\(R_3\)\\\(5.6k\Omega\)}] (0,5)
to [short] (0,4)
to [short] (-6,4)
to [C,l_=\parbox{1cm}{\centering\(C_1\)\\\(4.7\mu F\)}] (-6,1)
to [short] (0,1)
(-3,4)to [R,l_=\parbox{1cm}{\centering\(R_4\)\\\(10k\Omega\)},*-*] (-3,1)
(3,6) to [short] (3,4)
to [R,l_=\parbox{1cm}{\centering\(R_2\)\\\(39k\Omega\)}] (5,4)
to [short] (5,6)
to [R,l=\parbox{1cm}{\centering\(R_1\)\\\(47k\Omega\)}] (3,6)
;
\end{circuitikz}
\end{document}
输出
为了更轻松地排版单元,请考虑使用该siunitx
包。
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage[american,siunitx]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw
(0,4) to [C,l_=\parbox{1cm}{\centering\(C_2\)\\\(\SI{2.2}{\micro\farad}\)},v^=\(v_c\),*-*] (0,1)
to [short] (0,0)
to [ospst=\mbox{$t = \SI{0}{\second}$}] (6,0)
to [battery,l=$E$,v_=\SI{45}{\volt}] (6,5)
to [short] (5,5)
to [open,*-*] (3,5)
to [R=\parbox{1cm}{\centering\(R_3\)\\\(\SI{5.6}{\kilo\ohm}\)}] (0,5)
to [short] (0,4)
to [short] (-6,4)
to [C,l_=\parbox{1cm}{\centering\(C_1\)\\\(\SI{4.7}{\micro\farad}\)}] (-6,1)
to [short] (0,1)
(-3,4)to [R,l_=\parbox{1cm}{\centering\(R_4\)\\\(\SI{10}{\kilo\ohm}\)},*-*] (-3,1)
(3,6) to [short] (3,4)
to [R,l_=\parbox{1cm}{\centering\(R_2\)\\\(\SI{39}{\kilo\ohm}\)}] (5,4)
to [short] (5,6)
to [R,l=\parbox{1cm}{\centering\(R_1\)\\\(\SI{47}{\kilo\ohm}\)}] (3,6)
;
\end{circuitikz}
\end{document}