8

I've been trying to use relative coordinates to make my drawings more precise but it seems I don't know how the command \node works since I've been having this problem while connecting a circuit element to another:

enter image description here

I'm trying to eliminate the blank between the two wires.

This is the minimal code:

\documentclass{book}
\usepackage[siunitx,RPvoltages]{circuitikz} %Circuit Schematics/Diagram
\usetikzlibrary{arrows,shapes,calc,positioning}
\begin{document}
    \begin{circuitikz}
            \path (0,0) coordinate (C);
            % Comparatore
            \path (C) + (0,-1) + (1,0) coordinate (com) node[above]{};
            \path (com) + (1.5,-1) node[op amp] (comp) {};
            % Collegamenti Comparatore
            \node (G1) at ([shift=({-1.3cm,0cm})]comp.-) {};
            \draw (G1) -- (comp.-);
            \node (G2) at ([shift=({-1.3cm,0cm})]comp.+) {};
            \draw (G2) -- (comp.+);
            \draw (C) -- (G1); % Collegamento Rettificatore - Comparatore
        \end{circuitikz}
\end{document}

Thanks for any help!

2 Answers 2

10

enter image description here

Sorry. I went lost in your code, so I write new one, which reproduce desired result. I preserve coordinate (C) regardless that it is not needed for drawing this picture.

\documentclass[margin=3mm]{standalone}
\usepackage[siunitx,RPvoltages]{circuitikz} %Circuit Schematics/Diagram
\usetikzlibrary{arrows,shapes,calc,positioning}

\begin{document}
    \begin{circuitikz}
            % Collegamenti Comparatore
\node   (comp)  [op amp, right, anchor=-] {};
\draw   (comp.-)  -- ++ (-1,0) coordinate (C)
                  -- ++ ( 0,1)
        (comp.+)  -- (C |- comp.+)
        ;
    \end{circuitikz}
\end{document}
1
  • 1
    My sincere compliments for the sinthetic code :-)
    – Sebastiano
    Jul 6, 2019 at 10:03
13

Although the answer by Zarko is correct, the problem in your code (apart a bit of strange path building) is this line:

\node (G1) at ([shift=({-1.3cm,0cm})]comp.-) {};

and you can see it if you substitute your code with:

 \node [draw=red](G1) at ([shift=({-1.3cm,0cm})]comp.-) {};

which gives:

detail of node G1

Nodes have a minimum size, and when they are connected the connection goes to the "neareast" border. This is why in this case you should use \coordinate, which have no size.

If you insist on nodes, you should then connect to the center anchor:

 \draw (G1.center) -- (comp.-);
 \draw (C) -- (G1.center); % Collegamento Rettificatore - Comparatore

connecting to center anchor

although this is still sub-optimal:

bad connection

and this is why the accepted solution is better.

Just as an additional bonus, you can use my \coord() macro to show where your path is going...

\documentclass{book}
\usepackage[siunitx,RPvoltages]{circuitikz} %Circuit Schematics/Diagram
\usetikzlibrary{arrows,shapes,calc,positioning}
\def\coord(#1){node[circle, red, draw, inner sep=1pt,pin={[red, overlay, inner sep=0.5pt, font=\tiny, pin distance=0.1cm, pin edge={red, overlay,}]45:#1}](#1){}}
% \def\coord(#1){coordinate(#1)}
\begin{document}
    \begin{circuitikz}
            \path (0,0) \coord (C);
            % Comparatore
            \path (C) + (0,-1) \coord(1) + (1,0) \coord (com) node[above]{};
            \path (com) + (1.5,-1) \coord(3) node[op amp] (comp) {};
            % Collegamenti Comparatore
            \node [draw=red](G1) at ([shift=({-1.3cm,0cm})]comp.-) {};
            \path (G1) \coord(g1 center) (comp.-) \coord(-) (G1.north) \coord(g1 north);
            \draw (G1) -- (comp.-);
            \node (G2) at ([shift=({-1.3cm,0cm})]comp.+) {};
            \draw (G2) -- (comp.+);
            \path (G2) \coord(g2 center) (comp.+) \coord(+);
            \draw (C) -- (G1); % Collegamento Rettificatore - Comparatore
        \end{circuitikz}
\end{document}

showing coordinates

2
  • 2
    Thank you! Your macro looks extremely useful for identifying the position of the various anchors of components, which I've been having trouble with. Much appreciated. Jul 6, 2019 at 15:01
  • 1
    +1 but I do not see why you are so critical with your answer. The unfortunate feature will be gone immediately if you use \draw (C) -- (G1.center) -- (comp.-); or \draw (C) |- (comp.-); or \draw (comp.-) -| ++(-1,1);. The second and third options do not even require the center anchor. (Similarly Zarko's answer could be made "more concise" using \draw (comp.-) -| ++ (-1,1) coordinate (C) (comp.+) -- (C |- comp.+); or \draw (comp.-) -| ++ (-1,1) (comp.+) --++(-1,0);.)
    – user121799
    Jul 7, 2019 at 14:00

You must log in to answer this question.

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