[Tex/LaTex] CircuitTikZ – Combine Tripoles with resistors

circuitikztikz-pgf

I'm just learning how to use CircuitTikZ to draw circuits, and I am trying to draw a good looking BJT biasing circuit. But I am having making the resistors across from each other look even, and since there are no examples of combining tripoles with bipoles in the documentation I'm a little confused about whether or not I am doing this the best way. Here is my code:

\documentclass{article}
\usepackage{circuitikz}
\usepackage{amsmath}
\usepackage{SIunits}
\usepackage{circ}

\begin{document} 

Single Transistor discrete BJT biasing circuit:
\begin{center}
\begin{circuitikz}[scale=1.4]
\draw (0,0) node[ground] {};
\draw (0,0) to[R=$R_2$] (0,2);
\draw (0,2) to[R=$R_1$, *-] (0,4) -- (2,4);
\draw (2,2) node[pnp] (pnp) {}
    (pnp.B) -- (0,2);
\draw (2,4) to[R=$R_C$] (pnp.E);
\draw (2,0) node[ground] {};
\draw (2,0) to[R=$R_E$] (pnp.C);
\end{circuitikz}
\end{center}

\end{document}

I would like to have the top and bottom resistors at the same height if possible. Any help would be greatly appreciated!

Best Answer

The components in circuitikz are always placed midway between the coordinates of the paths they belong to, so you have to make sure the parallel paths start and end on the same heights in order to get identical vertical placement of the components.

The "dirty" way to do this is to just add additional points on the paths:

\documentclass{article}
\usepackage{circuitikz}
\usepackage{amsmath}
\usepackage{siunitx} % Preferred over SIunits
\begin{document} 

Single Transistor discrete BJT biasing circuit:
\begin{center}
\begin{circuitikz}[scale=1.4]
\draw (0,0) node[ground] {};
\draw (0,0) to[R=$R_2$] (0,1.4) -- (0,2);
\draw (0,2) -- (0,2.6) to[R=$R_1$] (0,4) -- (2,4);
\draw (2,2) node[pnp] (pnp) {}
    (pnp.B) [short,-*] to (0,2); % "short" is a plain wire
\draw (2,4) to[R,l_=$R_C$] (2,2.6) -- (pnp.E); % Switch label side
\draw (2,0) node[ground] {};
\draw (2,0) to[R=$R_E$] (2,1.4) -- (pnp.C);
\end{circuitikz}
\end{center}

\end{document}

enter image description here

A more "proper" way would be to use the \let \p<number> = (<coordinate>) in ..., which saves a coordinate in a local variable and lets you access the x and y components through \x<number> and \y<number>. You can then save the emitter and collector coordinates and use their y components in the end points for the wires with the resistors.

\documentclass{article}
\usepackage{circuitikz}
\usepackage{amsmath}
\usepackage{siunitx}
\begin{document} 

Single Transistor discrete BJT biasing circuit:
\begin{center}
\begin{circuitikz}[scale=1.4]
\draw (2,2) node[pnp] (pnp) {}
    (pnp.B) [short,-*] to (0,2);
\draw let \p1=(pnp.C),\p2=(pnp.E) in 
  (0,0) node [ground] {}
  to [R=$R_2$] (0,\y1) -- (0,2) -- (0,\y2) 
  to [R=$R_1$] (0,4) -- (2,4);
\draw (2,4) to [R,l_=$R_C$] (pnp.E);
\draw (2,0) node[ground] {};
\draw (2,0) to [R=$R_E$]  (pnp.C);
\end{circuitikz}
\end{center}

\end{document}
Related Question