5

I'm new in this and I want to do this circuit in LaTeX

Power electric system

1

1 Answer 1

4

There are a number of ways to draw circuits (speaking of TikZ of course):

  1. the circuitikz package;
  2. the circuits library directly provided by TikZ (to be loaded via \usetikzlibrary{circuits});
  3. manually.

Today let's go for manual approach.

Basically the first thing to do is to draw the symbol for the voltage source. One of course can go at low level and work with PGF, but I don't think it worth (moreover time is always scarse). So, as usual, it is possible to play with the so useful late options like append after command:

\tikzset{sin v source/.style={
  circle,
  draw,
  append after command={
    \pgfextra{
    \draw
      ($(\tikzlastnode.center)!0.5!(\tikzlastnode.west)$)
       arc[start angle=180,end angle=0,radius=0.425ex] 
      (\tikzlastnode.center)
       arc[start angle=180,end angle=360,radius=0.425ex]
      ($(\tikzlastnode.center)!0.5!(\tikzlastnode.east)$) 
    ;
    }
  },
  scale=1.5,
 }
}

This requires the calc library. The document is:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{sin v source/.style={
  circle,
  draw,
  append after command={
    \pgfextra{
    \draw
      ($(\tikzlastnode.center)!0.5!(\tikzlastnode.west)$)
       arc[start angle=180,end angle=0,radius=0.425ex] 
      (\tikzlastnode.center)
       arc[start angle=180,end angle=360,radius=0.425ex]
      ($(\tikzlastnode.center)!0.5!(\tikzlastnode.east)$) 
    ;
    }
  },
  scale=1.5,
 }
}
\begin{document}
\begin{tikzpicture}
\draw
(0,0) node [sin v source] (v1) {};
\end{tikzpicture}
\end{document}

The result:

enter image description here

I guess the sin v source is far from being perfect when the node requires another scaling, but for the answering purpose it's sufficient.

Now we're ready to draw the rest. The idea is to use one path, starting from the upper left part of the picture, going right and then below. Code is commented for clarity.

The left part:

\begin{tikzpicture}
\draw
(0,0) node [sin v source] (v1) {} % placing the left most source
(v1.north)--++(0,0.5) coordinate(v1-up) % wire going up: store the point
(v1-up)--++(-0.5,0) % left from v1-up
(v1-up)--++(2,0) node[right]{1} % right from v1-up, setting 1
coordinate[pos=0.5](v1-r) % identifying first departing point from v1-up
coordinate[pos=0.75](v1-rr) % identifying second departing point from v1-up
;
\end{tikzpicture}

enter image description here

Adding the right part of the picture:

\begin{tikzpicture}
\draw
(0,0) node [sin v source] (v1) {} % placing the left most source
(v1.north)--++(0,0.5) coordinate(v1-up) % wire going up: store the point
(v1-up)--++(-0.5,0) % left from v1-up
(v1-up)--++(2,0) node[right]{1} % right from v1-up, setting 1
coordinate[pos=0.5](v1-r) % identifying first departing point from v1-up
coordinate[pos=0.75](v1-rr) % identifying second departing point from v1-up
% - - - - - - - -
% right part
(v1-rr)--++(0,-0.25)--++(5,0)--++(0,0.25) % path reaching the right part of the picture
coordinate(v2-ll) % storing the coordinate
(v2-ll)--++(-0.5,0) node[left]{2} % setting 2
(v2-ll)--++(2,0) % going right from our stored coordinate
coordinate[pos=0.25](v2-l) % first departing point right of v2-ll
coordinate[pos=0.75](v2-up) % this will be the up part of the arrow
;
\end{tikzpicture}

enter image description here

As I'm lazy, I won't add immediately the arrow. Indeed, there's one path: adding globally an arrow option like \draw[-stealth] can't be done (as it applies for all "partial" paths we already drawn). Of course this wouldn't be a problem by exploiting the decorations library, but the simpler approach is just on line of code more.

Lower part:

\begin{tikzpicture}
\draw
(0,0) node [sin v source] (v1) {} % placing the left most source
(v1.north)--++(0,0.5) coordinate(v1-up) % wire going up: store the point
(v1-up)--++(-0.5,0) % left from v1-up
(v1-up)--++(2,0) node[right]{1} % right from v1-up, setting 1
coordinate[pos=0.5](v1-r) % identifying first departing point from v1-up
coordinate[pos=0.75](v1-rr) % identifying second departing point from v1-up
% - - - - - - - -
% right part
(v1-rr)--++(0,-0.25)--++(5,0)--++(0,0.25) % path reaching the right part of the picture
coordinate(v2-ll) % storing the coordinate
(v2-ll)--++(-0.5,0) node[left]{2} % setting 2
(v2-ll)--++(2,0) % going right from our stored coordinate
coordinate[pos=0.25](v2-l) % first departing point right of v2-ll
coordinate[pos=0.75](v2-up) % this will be the up part of the arrow
% - - - - - - - -
% lower part
(v1-r)--++(0,-0.25)--++(2.625,-2)--++(0,-0.25) % down path (*)
coordinate(v3-l) % storing the point
(v3-l)--++(-0.25,0) % going left
(v3-l)--++(1,0) % going right
coordinate[pos=0.375](v3-up) % this will be the up part of the second source 
coordinate[pos=0.75](v3-r) % identifying the point to connect with the right part of the picture
(v3-up) --++(0,-0.25) node[below,sin v source]{} % attaching the v source
(v3-r) --++(0,0.25)--++(2.625,2)--(v2-l) % path to the upper right part
% magically we don' need to replicate in the reverse way (*) completely since
% we have store the coordinate; since we have been smart with the coordinates it's completely simmetric ;) 
;
\end{tikzpicture}

enter image description here

The missing arrow has just been inserted with:

\draw[-stealth](v2-up)--++(0,-0.5cm); % down arrow

So I guess it's finished:

enter image description here

2
  • I’d use edges instead of \pgfextra (which misses interruptpath). Nov 16, 2013 at 10:46
  • @Qrrbrbirlbel: I suppose in that case reducing the scale would be even worst than the current approach. Nov 16, 2013 at 10:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .