在 circuitikz 电阻器内放置标签

在 circuitikz 电阻器内放置标签

我试图将 circuitikz 中(欧洲)电阻器的标签放置在电阻器内部, 我想要的是 但它会自动将它们放置在盒子旁边,我得到了以下信息:

我得到的是:

\documentclass[12pt,a4paper]{article}
\usepackage{circuitikz}
\begin{document}

\begin{circuitikz}[scale = 0.5,european]
            % start points
            \coordinate[label=above:B] (B) at (0,0);
            \coordinate[label=above:A] (A) at (0,5);
            \foreach \i in {A,B} {
                \fill (\i) circle (2pt);
            }
            \draw (B) to (4,0) to (4,-1) to[R, label={$2R$}] (8,-1) to (8,0);
            \draw (4,0) to (4,1) to[R, label={$2R$}] (8,1) to (8,0) to (12,0) to[R, l_={$R$}] (12,5) to[] (11,5);
            \draw (A) to[] (1,5) to (1,3) to[R, label={$2R$}] (11,3) to[] (11,5);
            \draw (1,5) to[R, label={$R$}] (6,5) to[R, label={$R$}] (11,5);
        \end{circuitikz}

\end{document}

答案1

嗯,这实际上不受支持。大多数组件都会出错,并且的想法circuitikz是您可以从切换europeanamerican并且仍然有一个有效的电路......

但你可以诱使它工作:

\documentclass[12pt,a4paper]{article}
\usepackage[RPvoltages]{circuitikz}
\begin{document}

\begin{circuitikz}[scale = 0.5,european]
            % start points
            \coordinate[label=above:B] (B) at (0,0);
            \coordinate[label=above:A] (A) at (0,5);
            \foreach \i in {A,B} {
                \fill (\i) circle (2pt);
            }
            % name the node, and...
            \draw (B) to (4,0) to (4,-1) to[R, name=R1] (8,-1) to (8,0);
            % add the thing
            \node  at (R1.center) {$R$};
            \draw (4,0) to (4,1) to[R, label={$2R$}] (8,1) to (8,0) to (12,0) to[R, l_={$R$}] (12,5) to[] (11,5);
            \draw (A) to[] (1,5) to (1,3) to[R, label={$2R$}] (11,3) to[] (11,5);
            \draw (1,5) to[R, label={$R$}] (6,5) to[R, label={$R$}] (11,5);
        \end{circuitikz}
\end{document}

在此处输入图片描述

您还可以使用一致的命名方案来自动化它们:

\documentclass[12pt,a4paper]{article}
\usepackage[RPvoltages]{circuitikz}
\begin{document}
\begin{circuitikz}[scale = 0.5,european]
            % start points
            \coordinate[label=above:B] (B) at (0,0);
            \coordinate[label=above:A] (A) at (0,5);
            \foreach \i in {A,B} {
                \fill (\i) circle (2pt);
            }
            % name the nodes Rx for R and 2Rx for 2R, and...
            \draw (B) to (4,0) to (4,-1) to[R, name=R1] (8,-1) to (8,0);
            \draw (4,0) to (4,1) to[R, name=2R1] (8,1) to (8,0) to (12,0) to[R, name=R2] (12,5) to[] (11,5);
            \draw (A) to[] (1,5) to (1,3) to[R, name=2R2] (11,3) to[] (11,5);
            \draw (1,5) to[R, name=R3] (6,5) to[R, name=R4] (11,5);
            % add labels
            \foreach \n in {1,...,4} \node at (R\n.center) {$R$};
            \foreach \n in {1,2} \node at (2R\n.center) {$2R$};
        \end{circuitikz}
\end{document}

在此处输入图片描述

相关内容