0

Basically, I have this code:

\begin{figure}
    \begin{circuitikz} [american voltages, american currents]
        \draw 
            (0,0) to (0, 0)
            to [ V = $V_g$, invert] (0, 2);
        \draw
            to (0, 2)
            to [ R, l_ = $R_1$ ] (2, 2);
        \path
            to (2, 2)
            to (0, 2);    
        \draw[dashed]
            to (0, 2)
            to (0, 4);
        \draw
            (0, 4)
            to [ voltmeter ] (2, 4);
        \draw[dashed]
            to (2, 4)
            to (2, 2);
        \path
            (2, 4);
        \draw
            (2, 4)
            to [ voltmeter ] (4, 4);
        \draw[dashed]
            to (4, 4)
            to (4, 2);
        \draw
            (4, 4)
            to [ voltmeter ] (6, 4);
        \draw[dashed]
            to (6, 4)
            to (6, 2);
        \path
            to (0, 4);
        \draw[dashed]
            to (0, 4)
            to (0, 6);
        \draw
            to (0, 6)
            to [ voltmeter ] (6, 6);
        \draw[dashed]
            to (6, 6)
            to (6, 4);
        \draw
            to (2, 2)
            to [ R, l_ = $R_2$ ] (4, 2)
            to [ R, l_ = $R_3$ ] (6, 2)
            to (6, 0);
        \path
            to (0, 0);
        \draw
            to (0, 0)
            to [ ammeter ] (6, 0);
        \end{circuitikz}
\end{figure}

Which should print out like this (which does on the PDF viewer). Preview seen inside the editor.

But instead, it prints out like this on the PDF file:

Actual printout in the PDF file.

Why does this happen and how can I fix it?

8
  • Welcome to tex.sx. What kind of printer are you using, and what is its resolution? Commented Aug 30, 2023 at 16:12
  • Hello, thank you. I'm using Overleaf, not really sure what printer it uses. Commented Aug 30, 2023 at 16:23
  • Overleaf is (remote) editor and it doesn't use any printer but compile your code to .pdf file, which you can see in Overleaf preview window. If there are missed some lines, than they are not defined in your code. BTW, your code is a bit strange and if I inserted it in some my working document doesn't produce first image in your question. You should fix your code first.
    – Zarko
    Commented Aug 30, 2023 at 16:51
  • You should be aware that command \path doesn't draw visible lines.
    – Zarko
    Commented Aug 30, 2023 at 16:57
  • @Zarko this is strange code, yes - maybe machine-produced? But the main problem is the (wrong) \draw to ... idiom, which generates code that seems to be interpreted differently by different PDF processors.
    – Rmano
    Commented Aug 30, 2023 at 17:25

2 Answers 2

2

Let's try to simplify the problem. If I compile this small part (I added the red dot to have a reference to (0,0)):

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz} [american voltages, american currents]
        \draw
        (0,0) to (0,0) node[circ,red]{}
            to [ V = $V_g$, invert] (0, 2);
        \draw
            to (0, 2)
            to [ R, l_ = $R_1$ ] (2, 2);
\end{circuitikz}
\end{document}

you have the following:

enter image description here

See the gap? This is because your second draw uses \draw to (0,2) and to needs a starting coordinate explicitly. The first (0,0) to (0,0) also is doing nothing...

If you change the code to

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz} [american voltages, american currents]
    \draw
    (0,0) node[circ,red]{}
    to [ V = $V_g$, invert] (0, 2);
    \draw
    (0, 2)
    to [ R, l_ = $R_1$ ] (2, 2);
\end{circuitikz}
\end{document}

You have the correct one:

enter image description here

The current point is not "reminded" from one draw to another one, in other words. BTW, the code is much easier to write (I removed the red dot) as:

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz} [american voltages, american currents]
    \draw
    (0,0)
    to [ V = $V_g$, invert] (0, 2)
    to [ R, l_ = $R_1$ ] (2, 2);
\end{circuitikz}
\end{document}

Also, the \path elements are basically doing nothing here.

What is strange is that you have a previsualization with the lines... I have consistent white gaps in both preview and printing.

A possible code for your drawing (but you should try to reduce the number of different paths) could be:

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz} [american voltages, american currents]
    \draw (0,0)
    to [ V = $V_g$, invert] (0, 2)
    to [ R, l_ = $R_1$ ] (2, 2);
    \draw[dashed] (0, 2) -- (0, 4);
    \draw (0, 4) to [ voltmeter ] (2, 4);
    \draw[dashed] (2, 4) -- (2, 2);
    \draw (2, 4) to [ voltmeter ] (4, 4);
    \draw[dashed] (4, 4) to (4, 2);
    \draw (4, 4) to [ voltmeter ] (6, 4);
    \draw[dashed] (6, 4) -- (6, 2);
    \draw[dashed] (0, 4) -- (0, 6);
    \draw (0, 6) to [ voltmeter ] (6, 6);
    \draw[dashed] (6, 6) to (6, 4);
    \draw (2, 2) to [ R, l_ = $R_2$ ] (4, 2)
        to [ R, l_ = $R_3$ ] (6, 2)-- (6, 0);
    \draw (0, 0) to [ ammeter ] (6, 0);
\end{circuitikz}
\end{document}

enter image description here

2

One more version how to correct draw your sheme in one loop and add dashed lines separate:

\documentclass[margin=3mm]{standalone}
\usepackage{circuitikz}

\begin{document}
    \begin{circuitikz}[american voltages, american currents]
\draw   (0,0)   to [V = $Vg$, invert]  (0,2)
                to [R = $R_1$ ] (2,2)
                to [R = $R_2$ ] (4,2)
                to [R = $R_3$ ] (6,2)
                to [short]      (6,0)
                to [ammeter, invert, mirror]    (0,0)
        (0,4)   to [voltmeter]  (2,4)
                to [voltmeter]  (4,4)
                to [voltmeter]  (6,4)
        (0,6)   to [voltmeter]  (6,6);
\draw[dash pattern=on 2mm off 1mm]
        (0,2) -- (0,6)
        (2,2) -- (2,4)
        (4,2) -- (4,4)
        (6,2) -- (6,6);
    \end{circuitikz}
\end{document}

enter image description here

You must log in to answer this question.

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