# How can I get the TikZ calc library to calculate some point coordinates correctly?

I have used the code shown below to draw a static CMOS inverter. I have tried to use the TikZ library calc to calculate the point at which drains of the PMOS and the NMOS devices meet; and the mid-point of the line which connects the gates of the two devices. Apparently calc gets the y coordinates of the points right. However, calc seems to get the x coordinates of the points wrong. What could I be doing wrong?

Here is the TikZ code:

\documentclass{standalone}
\usepackage[americaninductors]{circuitikz}
\usetikzlibrary{calc}
\begin{document}
\begin{circuitikz}
\draw
% Draw MOSFETs:
(0,0) node [pigfete,yscale=-1,anchor=S] (M1) {}
(M1.D) node[nigfete,anchor=D] (M2) {}
(M1.G)--(M2.G) % The line connecting the gates of the MOSFETs.
;
% Draw the power rails:
\draw ($(M1.S)-(2.0,0)$) -- (M1.S) -- ($(M1.S)+(1.2,0)$);
\draw ($(M2.S)-(2.0,0)$) -- (M2.S) -- ($(M2.S)+(1.2,0)$);
% Input and output nodes:
\node (I) at ($0.5*(M2.G)+0.5*(M1.G)$) {}; % The mid-point between the gates.
\node (O) at (M1.D) {}; % The point at which the drains of the MOSFETs are conneted.
% The Input and output lines.
\draw ($(I)-(.8,0)$) -- (I);
\draw (O) -- ($(O)+(0.8,0)$);
\end{circuitikz}
\end{document}


Here is the figure that I get: Note that that input and the output lines are not connected to the rest of the circuit. Can we attribute the problem of the lines not being connected, to the rest of the circuit, to the way I am using calc?

## The code:

\documentclass{standalone}
\usepackage[americaninductors]{circuitikz}
\usetikzlibrary{calc}
\begin{document}
\begin{circuitikz}
\draw
% Draw MOSFETs:
(0,0) node [pigfete,yscale=-1,anchor=S] (M1) {}
(M1.D) node[nigfete,anchor=D] (M2) {}
(M1.G)--(M2.G) % The line connecting the gates of the MOSFETs.
;
% Draw the power rails:
\draw ($(M1.S)-(2.0,0)$) -- (M1.S) -- ($(M1.S)+(1.2,0)$);
\draw ($(M2.S)-(2.0,0)$) -- (M2.S) -- ($(M2.S)+(1.2,0)$);
% Input and output nodes:
%\node (I) at ($0.5*(M2.G)+0.5*(M1.G)$) {}; % The mid-point between the gates.
\coordinate (I) at ($0.5*(M2.G)+0.5*(M1.G)$); % The mid-point between the gates.
%\node[outer sep=0pt,inner sep=0pt] (O) at (M1.D) {}; % The point at which the drains of the MOSFETs are conneted.
\coordinate (O) at (M1.D); % The point at which the drains of the MOSFETs are conneted.
% The Input and output lines.
\draw (I) -- ++(-0.8,0);
\draw (O) -- ++(0.8,0);
\end{circuitikz}
\end{document}


## The explanation:

TikZ \nodes add certain padding around them (in the outside, given by outer sep, and in the interior, given by inner sep. To prevent this extra space, is better to use \coordinates. Another option would be to kill those seps using \node[inner sep=0pt,outer sep=0pt] {};

• Thank you very much Gonzalo Medina you for the elegant solution to my problem. I have learned two new things: (a) The use of \coordinate; and (b) the use of \node[inner sep=0pt,outer sep=0pt] {} to kill the padding around the nodes. Great stuff. – user24098 Nov 8 '14 at 3:00
• I was only able to get this to work by removing ,yscale=-1 from the pigefete line. (using circuitikz within pandoc) – ZuluDeltaNiner Apr 2 at 0:47