[Tex/LaTex] Working with perpendicular coordinates in circuitikz

circuitikzcoordinatestikz-pgf

Inspired by Paul Gessler's answer to this question, I decided to give it a try and adapt the following diagram to use perpendicular coordinates:

\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
    \begin{circuitikz}
        \draw
        (0,0) node[op amp] (opamp) {}
        (opamp.-) node(node1)[circ]{}
        (node1) -- ++(0,1.5) to[R] ++(1.5,0) node(node2){} to[short] ++(1.5,0) to[R] ++(0,-2)
        ;
    \end{circuitikz}
\end{document}

Desired output

Note that the last coordinates (0,-2) where found by trial and error. Thus, I tried to use perpendicular coordinates to avoid having to guess them. What follows is what I wrote. I simply defined the foo coordinate and followed Paul's answer. Was expecting to get exactly the same result, but unfortunately it won't complie:

\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
    \begin{circuitikz}
        \draw
        (0,0) node[op amp] (opamp) {}
        (opamp.-) node(node1)[circ]{}
        (node1) -- ++(0,1.5) to[R] ++(1.5,0) node(node2){} to[short] ++(1.5,0) coordinate (foo) to[R] (foo |- (opamp.out)) to[short] (opamp.out)
        ;
    \end{circuitikz}
\end{document}

Package pgf Error: No shape named (opamp is known. ...dinate (leftC) to[R] (leftC |- (opamp.out) (x3)

Package tikz Error: Giving up on this path. Did you forget a semicolon?. ...inate (leftC) to[R] (leftC |- (opamp.out))

What is causing this errors?

Best Answer

If you are specifying a perpendicular coordinate based on, say (a) and (b), then the syntax is

  • (a |- b)

or

  • (a -| b)

If you add brackets around the coordinates as well, you'll get errors. That is

  • (a |- (b))

will NOT work because TikZ will look for a shape or coordinate named (b rather than b.

Hence, your code can be corrected by omitting the additional brackets:

\documentclass[tikz,border=5pt]{standalone}
\usepackage{circuitikz}
\begin{document}
  \begin{circuitikz}
    \draw
    (0,0) node[op amp] (opamp) {} (opamp.-) node(node1)[circ]{} (node1) -- ++(0,1.5) to[R] ++(1.5,0) node(node2){} to[short] ++(1.5,0) coordinate (foo) to[R] (foo |- opamp.out) to[short] (opamp.out) ;
  \end{circuitikz}
\end{document}

corrected compilation result