[Tex/LaTex] Tikz obtain node coordinates

circuitikzcoordinatesnodes

In tikzpicture, how do I get a single coordinate of a node?

enter image description here

This is the circuit I'm making, and I need to know the x coordinate of the node (opamp.out) so that i can make R2 vertically aligned with that node, and link it with a vertical line.
This is my code for R2:

\draw (opamp.-) to [short,*-] ++(0,1) node{} to [R,l=$R_2$]
++(2,0);

where, instead of ++(2,0), I would like to input ++(opamp.out.x-opamp.-.x,0);

Best Answer

An alternative: use of orthogonal coordinate

(p -| q) refers to the point horizontally aligned with p and vertically aligned with q. The -| was chosen in such a way that it's easy to remember which is which; the - side is horizontal, and the | side is vertical. The CircuiTikz manual has further information.

Complete Examples:

Resulting Diagram

Code:

\documentclass[border=10pt,varwidth]{standalone}  
\usepackage{tikz}
\usepackage[american,siunitx]{circuitikz}
\usetikzlibrary{calc,positioning}
\begin{document}

An alternative solution

\begin{circuitikz}  
\draw
(0,0) node[op amp](opamp){}
(opamp.out) to[short,*-o] (2,0)node[]{} node[right]{$v_{out}$};
\draw (opamp.-) -- ++(-0.2,0) to[R,l_=$R_1$] ++ (-2,0)node[ground,rotate=-90]{};
\draw (opamp.+) to[short,-o] ++ (-0.5,0)node[left]{$V_{in}$};

\draw (opamp.-) to [short,*-] ++(0,1) node{} to [R,l=$R_2$] ([yshift=1cm]opamp.- -|opamp.out);
\end{circuitikz}

\medskip

@Astrinus' solution

\begin{circuitikz}
\draw
(0,0) node[op amp](opamp){}
(opamp.out) to[short,*-o] (2,0)node[]{} node[right]{$v_{out}$};

\draw (opamp.-) -- ++(-0.2,0) to[R,l_=$R_1$] ++ (-2,0)node[ground,rotate=-90]{};
\draw (opamp.+) to[short,-o] ++ (-0.5,0)node[left]{$V_{in}$};

\draw let \p1=(opamp.out),\p2=(opamp.-) in (opamp.-) to [short,*-] ++(0,1) 
node{} to [R,l=$R_2$] ++($(\x1,0)-(\x2,0)$);
\end{circuitikz}

\end{document}
Related Question