3

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);

3
  • \draw let \p1=(opamp.out),\p2=(opamp.-) in (opamp.-) to [short,*-] ++(0,1) node{} to [R,l=$R_2$] ++($(\x1,0)-(\x2,0)$); Note that you have to \usetikzlibrary{calc}
    – Astrinus
    Commented Dec 11, 2014 at 9:55
  • Glad it worked. I've not tested it XD. I'll turn into an answer.
    – Astrinus
    Commented Dec 11, 2014 at 10:05
  • 1
    Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers.
    – Astrinus
    Commented Dec 12, 2014 at 17:14

2 Answers 2

3

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

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

Note that you have to \usetikzlibrary{calc}.

The let syntax let you alias the points with names \p1 ... \pN, where N is the number of points. Then, after in, you could access points' coordinates with the syntax \x1 .. \xN and \y1 .. \yN (I think it's possible to access also polar coordinates but honestly I don't remember the syntax :-8), matching the order of \p assignments.

The library calc let you make calculations with coordinates and get the resulting coordinates, with the syntax ($<calculations>$).

Look at pgfmanual.pdf or at "TikZ pour l'impatient" if you read french (I can't speak french at all, but since my mother language is neo latin I had absolutely no problem reading it).

You must log in to answer this question.

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