如何确保使用 circuitikz 的惠斯通电桥中的所有线路都连接起来?

如何确保使用 circuitikz 的惠斯通电桥中的所有线路都连接起来?

我最近发现了circuitikz一个很棒的,因为我需要说明一个对角配置的惠斯通电桥。我偶然发现了这个问题我修改了它以使其更加紧凑:

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usepackage[europeanresistors,americaninductors,americancurrents,siunitx]{circuitikz}

    \begin{document}
    
    \begin{circuitikz}[declare function = {hypo = 4; x = 1; r ={1/2};}]
        \ctikzset{label/align = straight}
        \draw(0,0) to [dcvsource , l= $V_\textrm{in}$] ++({hypo*sqrt(2) + 0},0);
        \draw(0,0) to[short, i = $I$] ++(0, -4) to[short, -*] ++(0, 0) node[label={below:$C$}](C){} to [R, l_= $R_1$, i>_= $I_\mathrm{A}$, -*] ++(45:hypo) node[label={above:$A$}](A){} to[R, l_=$R_2$, -*, fill=black] ++(-45:hypo) node[label = {below:$D$}](D){} to [short] ++(0, 0) to [short, i = $I$] ++(0,4);
        \draw(C) to[R, l^= $R_3$, i>^= $I_\mathrm{B}$, -*, fill=black] ++(-45:hypo) node[label = {below:$B$}](B){} to [R, l^=$R_4$] ++(45:hypo);
        \draw(A) to [rmeter, t=$V_\mathrm{out}$] (B);
    \end{circuitikz}
    
    \end{document}

一切看起来都很好,除了线在三个地方没有相交(在 C 处以及 A 与 B 之间):

在此处输入图片描述

这很奇怪,因为另一幅图问题看起来没什么问题(尽管我在电脑上运行它时也出现了同样的问题)。

我做错了什么?为什么线路没有正确连接?

答案1

所有带标签的节点都应替换为coordinate

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usepackage[europeanresistors,americaninductors,americancurrents,siunitx]{circuitikz}

    \begin{document}
    \begin{circuitikz}[
declare function = {hypo = 4; x = 1; r ={1/2};}
                    ]
\ctikzset{label/align = straight}
\draw (0,0) to [dcvsource , l= $V_\textrm{in}$] ++ ({hypo*sqrt(2) + 0},0);
\draw (0,0) to [short, i = $I$] ++(0,-4) 
            to [short, -*] ++(0, 0) coordinate[label={below:$C$}] (C)   % <---
            to [R, l_= $R_1$, i>_= $I_\mathrm{A}$, -*] ++(45:hypo) coordinate[label=$A$](A)
            to [R, l_=$R_2$, -*, fill=black] ++(-45:hypo) coordinate[label = below:$D$](D) 
            to [short] ++(0, 0) to [short, i = $I$] ++(0,4);
\draw(C)    to[R, l^= $R_3$, i>^= $I_\mathrm{B}$, -*, fill=black] ++(-45:hypo) coordinate[label=below:$B$](B)
            to [R, l^=$R_4$] ++(45:hypo);
\draw(A) to [rmeter, t=$V_\mathrm{out}$] (B);
    \end{circuitikz}
\end{document}

在此处输入图片描述

附录: 我们的电路代码可以更简单:

\documentclass[border=5mm]{standalone}
\usepackage[european]{circuitikz}

    \begin{document}
    \begin{circuitikz}
    \ctikzset{resistors/scale=0.8}
\draw (0,0) coordinate[label=left:$C$] (C)
            to [R, a=$R_1$,i>_=$I_\mathrm{A}$, *-*] ++ (3,3) coordinate[label=$A$] (A)
            to [R,a=$R_2$,fill=black, -*] ++ (3,-3) coordinate[label=right:$D$] (D)
            to [R,a=$R_4$,-*] ++ (-3,-3) coordinate[label=below:$B$] (B)
    (C)     to [R=$R_3$, fill=black,i>^=$I_\mathrm{B}$, *-*]  (B)
    (A)     to [rmeter, t=$V_\mathrm{out}$] (B)
    (D)     to [short, i = $I$] ++ (0,4)
            to [dcvsource, a=$V_\textrm{in}$] ++ (-6,0)
            to [short, i = $I$] (C);
    \end{circuitikz}
\end{document}

结果几乎相同:

在此处输入图片描述

答案2

在选定节点上:用户nodename.center

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usepackage[europeanresistors,americaninductors,americancurrents,siunitx]{circuitikz}
\begin{document}

\begin{circuitikz}[declare function = {hypo = 4; x = 1; r ={1/2};}]
    \ctikzset{label/align = straight}
    \draw(0,0) to [dcvsource , l= $V_\textrm{in}$] ++({hypo*sqrt(2) + 0},0);
    \draw(0,0) to[short, i = $I$] ++(0, -4) to[short, -*] ++(0, 0) node[label={below:$C$}](C){} to [R, l_= $R_1$, i>_= $I_\mathrm{A}$, -*] ++(45:hypo) node[label={above:$A$}](A){} to[R, l_=$R_2$, -*, fill=black] ++(-45:hypo) node[label = {below:$D$}](D){} to [short] ++(0, 0) to [short, i = $I$] ++(0,4);
    \draw(C.center) to[R, l^= $R_3$, i>^= $I_\mathrm{B}$, -*, fill=black] ++(-45:hypo) node[label = {below:$B$}](B){} to [R, l^=$R_4$] ++(45:hypo);
    \draw(A.center) to [rmeter, t=$V_\mathrm{out}$] (B.center);
\end{circuitikz}

\end{document}

相关内容