3

I recently discovered circuitikz which is great because I need to illustrate a diagonally configured Wheatstone bridge. I came across this question which I modified to become more compact:

\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}

All appear to be fine except the lines do not intercept at three places (at C and between A and B):

enter image description here

This is strange because the image in the other question appears to be fine (although the same problem arises when I run it on my computer).

What am I doing wrong? Why are the lines not properly connected?

2
  • If you look at the circuitikz manual, the first entry in the FAQ section (8.1) will explain what's happening. Both the answer here are correct.
    – Rmano
    Jul 30, 2021 at 21:34
  • Thank you, @Rmano. I read the section you mentioned -- hilarious footnotes! Jul 31, 2021 at 9:27

2 Answers 2

5

All nodes with labels you should replace with 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}

enter image description here

Addendum: Code for our circuit can be simpler:

\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}

And result is almost the same:

enter image description here

1
  • Thank you, @Zarko. It works like a charm. Also thank you for the simplified version. Jul 31, 2021 at 9:28
4

On selected nodes: user 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}
2
  • Thank you, @Jesse op den Brouw. I wish I could accept both answers because yours is also correct! Jul 31, 2021 at 9:29
  • @naughty_waves: no problem. Jul 31, 2021 at 10:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .