# Draw dipoles and tripoles with blocks

In order to draw a circuitikz picture with a transformer, I have to draw the transformer first, as in the following code.

%Flyback
\begin{circuitikz}[scale = 1.5] \draw
(0,0) node[transformer, yscale=1.5](T) {}
(T.A2)
to [short] ($(T.A2)+(-1.5,0)$)
to [V, l=$V_S$, invert] ($(T.A1)+(-1.5,0)$)
to [nos, l=S] (T.A1)
(T.B1)
to [D, l=D] ++(2,0) coordinate (Node1)
to [short] ++(2,0)
to [R, l_=R, v^=$V_o$] ($(T.B2)+(4,0)$)
to [short] (T.B2)
(Node1)
to [pC, l_=C, *-*, invert] ($(T.B2)+(2,0)$)
%Transformer labels
(T.inner dot A1) node[circ]{}
(T.inner dot B2) node[circ]{}
($(T.base)+(0,0.3)$) node{$N_1$ : $N_2$}
;
\end{circuitikz}


It makes drawing quite difficult, as I have to draw the transformer first and draw the whole picture based on the anchors of that initial transformer,

Therefore, if I have to draw the following circuit, it is very hard.

So how to draw a circuit with a transformer "from left to right", for example taking the very south west coordinate as (0,0) and draw the picture based on that?

And another question, I check the manual of circuitikz and shows the next example:

I understand that the following code does the red rectangle:

\draw[red, thick] (1.5,2.5) rectangle (4.5,3.5)


But when I try to do that, LyX refuses to finish the compilation process. I installed only circuitikz from the MikTeX frontend, I can't find the tikz package. circuitikz can do that or I need another package?

• As for the last "extra-" question: You need a semicolon ; there. You will never find tikz package, because it is only a frontend of a larger package: pgf - and you must have pgf to have circuitikz working
– user156344
May 24, 2019 at 6:36
• Hi, i want to draw the 3rd circuit in my question, i want to know if exists a way to do it by starting with the input V1 and draw the transformer later in the code, when i already draw C1, Q1 and the "Control 1" block. May 24, 2019 at 6:42
• Why do you want to draw that way? Except when you have to deal with clipping or filling, you do not have to care about the drawing order in TikZ. You just have to draw in the easiest way; no need to draw strictly from input node to output node - you can draw from output to input, no problem.
– user156344
May 24, 2019 at 6:43
• I think I understand the question, and I edit your question to make it clearer. If I misunderstood your question, please rollback to the first revision.
– user156344
May 24, 2019 at 7:16

## 3 Answers

As I mentioned in the comments, LyX fails to complete the compilation because of the lack of a semicolon. Sometimes TikZ gives an error, but unfortunately sometimes it just runs forever.

I think I have found an answer for your main question. In order to draw "from left to right", you need to change the size of the transformer so that its height and its width are some integer dimensions. I find that the height and the width of the transformer is about 1.5 times as much as the value of bipoles/length (not figure out why it is not 1 or 2). Therefore, if I want its height to be 2cm, I have to add bipoles/length=1.333333cm.

Now as the height is 2cm, you can use normal Cartesian coordinates. The following code draws a simple figure with a transformer, but it is literally drawing from left to right.

\documentclass[margin=3]{standalone}
\usepackage[americaninductors]{circuitikz}
\begin{document}
\begin{circuitikz}
\ctikzset{bipoles/length=1.33333333cm} % 4/3 so that the height of the
% transformer is exactly 2
\draw[*-] (0,0) -- (1,0);
\draw[*-] (0,2) -- (1,2);
\node[transformer core] at (2,2) {};
\draw[-*] (3,0) -- (4,0);
\draw[-*] (3,2) -- (4,2);
\end{circuitikz}
\end{document}


Now, with this trick you can draw your complicated figure (I hope so). Good luck!

• The size of a transformer is controlled by \ctikzset{quadpoles/transformer/width=1.5} and \ctikzset{quadpoles/transformer/height=1.5}, and they are relative to the main bipoles/length, which by default is 1.4cm. You can play with that if you like... (I know, should be in the manual: I'll try to update that. Meanwhile, looking at pgfcirc.defines.tex can help). May 24, 2019 at 17:56
• And probably the ideal solution would be to make the horizontal leads optional, so that you can place at least one of the side of it "inline". Will try to do it. May 24, 2019 at 18:15

One can position the transformer using [anchor=A1]. Also, one can use the (A|-B) or (A-|B) protocol to locate the intersection of crossing lines.

\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}[scale = 1.5]
\draw
(0,0) coordinate (P1)
to [nos, l=S] ++(1.5,0)
node[transformer, yscale=1.5, anchor=A1] (T) {}
(T.A2)
to [short] (P1 |- T.A2)
to [V, l=$V_S$, invert] (P1);
\draw
(T.B1)
to [D, l=D] ++(2,0) coordinate (Node1)
to [short] ++(2,0) coordinate(P2)
to [R, l_=R, v^=$V_o$] (P2 |- T.B2)
to [short] (T.B2)
(Node1)
to [pC, l_=C, *-*, invert] (T.B2 -| Node1)
%Transformer labels
(T.inner dot A1) node[circ]{}
(T.inner dot B2) node[circ]{}
($(T.base)+(0,0.3)$) node{$N_1$ : $N_2$}
;
\end{circuitikz}
\end{document}


• +1, this is how I would do it. If you add [RPvoltages] to the options of circuitikz, the voltage will come out "righter" (for my side of the world, clearly... :-) ) May 24, 2019 at 18:01

While I think that John Kormylo's answer is probably the correct one for the available circuitikz (0.9.0), I just want to chime in to say this question prompted me to add an option that will be available since 0.9.1 that will allow to remove the horizontal "baffles" for the quadpoles.

That will give you a lot more flexibility when drawing your circuit.

You can see the pull request at https://github.com/circuitikz/circuitikz/pull/208