# How to combine two dipole and tripoles efficiently in circuitikz?

I'm trying to learn how to use circuitikz to draw some circuit diagrams. So far it is going pretty well, except that now I've run into a problem when trying combine dipole circuit elements (such as resistors) with tripole elements like operational amplifiers.

For example, I would like to attach the inverting input of the amplifier (the negative terminal) at the end of the resistor in the following circuit, as well as attach something to the positive terminal and the output. In my code below, I've managed to do this, but just by guessing the right coordinates for the op amp, and things don't align up nicely. With more op amps, in more complicated circuits, my approach really does not seem to be the most optimal one.

Is there a better way of approaching this?

Edit: I found this link for a similar question involving transistors: CircuitTikZ - Combine Tripoles with resistors, however I am not sure how to adapt this to my question. How do I know where to place the op amp so that it lines up nicely with the resistors?

\documentclass{article}
\usepackage[american voltages, american currents,siunitx]{circuitikz}
\begin{document}
\begin{circuitikz}
% the voltage source and the resistor
\draw (0,0) node [ground] {} to [V=\SI{1}{V}] (0,3)
to [R=\SI{1}{k\ohm}] (3,3);

% the opamp
\draw (4,2.5) node [op amp] {};

% the ground at the + terminal
\draw (3,2) to (2.5,2) node [ground] {};

% the output
\draw (5,2.5) to (6,2.5)
to [R=\SI{1}{k\ohm}] (6,0) node [ground] {};
\end{circuitikz}
\end{document}


-

The approach I use is to define my coordinates and nodes, then insert the major components (not necessarily in that order). I use relative coordinates for the nodes. The advantage is that you don't have to fiddle around so much with 'trial and error' placement of everything. The code however is a bit longer. The "on grid" option centers the nodes onto grid coordinates. [tikz manual, section 16.5.3 v 2.10 cvs 2011.01 version]

\documentclass{article}
\usepackage[american]{circuitikz}
\usetikzlibrary{positioning}
\usepackage{siunitx}
\begin{document}

\begin{circuitikz}[on grid]
\draw   (0,1) node {Basic opamp};
% Define coordinates and nodes
\node (vi)  {};
\node (a) [right=2 of vi] [label=below:$a$]{};
\node[ground](gnn)  [below=1.0 of a,xshift=5mm] {};
\node[ground](gnp)  [below=2.5 of vi] {};
\node[op amp](oa)   [right=2 of a, yshift=-5mm]{};
\node (vo)  [right=0.6 of oa.out]{};
\node[ground](gnd)  [below=2 of vo] {};

% connect coordinates, inputs, outputs, and components, i.e. draw the circuit
\draw (gnp) to[V=\SI{1}{V}] (vi);
\draw (vi)  to[R=1 \SI{k\ohm}] (oa.-);
\draw (oa.+) -| (gnn) node[ground]{};
\draw (oa.out)  to[short]   (vo);
\draw (vo)  to[R=\SI{1}{k\ohm}]  (gnd);
\end{circuitikz}
\end{document}

-

I would scale the opamp by using yscale = 1.01. It does fit perfectly and you don't need to change all your coordinates.

\documentclass[14pt]{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}[american voltages]
%the voltage source and the resistor
\draw (0,0) node [ground] {}
to [V] (0,3)
to [R] (3,3);

% the opamp
\draw (4,2.5) node [op amp,yscale=1.01] {};

% the ground at the + terminal
\draw (3,2)
to (2.5,2) node [ground] {};

% the output
\draw (5,2.5)
to (6,2.5)
to [R] (6,0) node [ground] {};
\end{circuitikz}
\end{document}


-