# How to draw circled transistors

How to draw a circled transistor in circuitikz?

I did not find any info about circled transistors in circuitikzmanual.pdf.

-

Since circuitikz is built upon TikZ, you can use \draw to draw a circle:

\documentclass{article}
\usepackage{circuitikz}

\begin{document}

\begin{circuitikz}
\draw (0,0) node[npn] (npn) {}
(npn.base) node[anchor=east] {B}
(npn.collector) node[anchor=south] {C}
(npn.emitter) node[anchor=north] {E};
\draw ($(npn)-(0.18,0)$) circle [radius=18pt];
\end{circuitikz}

\end{document}


As it is noted in the comments, in the original solution the circle was wrong centered; Kroll suggested using the barycentre of the triangle with vertices in the base, the collector and the emitter, but this also produces the wrong result, as can be seen in the example below (which uses barycentric coordinates to easily obtain the coordinates for the center; the calculations are done automatically using a \CalcC command whose argument is the name used for the transistor):

\documentclass{article}
\usepackage{circuitikz}

\def\CalcC#1{%
\coordinate (base) at (#1.base);
\coordinate (collector) at (#1.collector);
\coordinate (emitter) at (#1.emitter);
}

\begin{document}

\begin{circuitikz}
\draw (0,0) node[npn] (name) {}
(name.base) node[anchor=east] {B}
(name.collector) node[anchor=south] {C}
(name.emitter) node[anchor=north] {E};
\CalcC{name}
\end{circuitikz}

\end{document}


A little horizontal shift (obtained with a variation of the barycentric coordinate associated to the base anchor), produces a much better result:

\documentclass{article}
\usepackage{circuitikz}

\def\CalcC#1{%
\coordinate (base) at (#1.B);
\coordinate (collector) at (#1.C);
\coordinate (emitter) at (#1.E);
}

\begin{document}

\begin{circuitikz}
\draw (0,0) node[npn] (name) {}
(name.base) node[anchor=east] {B}
(name.collector) node[anchor=south] {C}
(name.emitter) node[anchor=north] {E};
\CalcC{name}
\end{circuitikz}

\end{document}


-
It is wrong centered. The center of the circle must be in the center of the transistor. – Kroll Apr 18 '12 at 22:52
i.e. in the center of the collector-emitter triangle or the center of the base-collector-emitter trapezoid. I think it's too complicated to define it manually. This feature should be implemented inside circuitikz. – Kroll Apr 18 '12 at 23:09
@Kroll:please see my updated answer; now the center is automatically calculated using barycentric coordinates and you can easily change the horizontal component in the definition of \CalcC to place the center automatically in the desired position. Of course, the ultimate solution would be to ask the author of circuitikz to define this kind of transistor. – Gonzalo Medina Apr 19 '12 at 1:04