Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to draw a circled transistor in circuitikz?

enter image description here

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

share|improve this question
add comment

1 Answer

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}

enter image description here

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);
\draw (barycentric cs:base=0.5,collector=0.5,emitter=0.5) circle [radius=14pt];
}

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

enter image description here

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);
\draw (barycentric cs:base=0.32,collector=0.5,emitter=0.5) circle [radius=14pt];
}

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

enter image description here

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.