2

im trying to fit circuits in a documents but the coordinates are not working well.

Here is the cricuits that I'm trying to organize:

enter image description here

I would like to move the circuits to the left, here is the code:

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage{tikz}  
\usepackage{mathtools}  
\usepackage[american]{circuitikz} 
\usepackage{enumitem}
\usetikzlibrary{shapes,arrows}  
\renewcommand*\contentsname{Contenido} 
\begin{document} 


\begin{circuitikz}   

%Primer circuito
\draw (-6,-1.5) 
to [V, v=$V_i$,invert] (-6,3)
to [short] (-3,3)  
to [diode] (-3,1)   
(-3,3) to [short] (0,3) 
to [battery, label = 1V] (0,1)  
(-3,1) to [R=$1k\Omega $,v = $V_o$] (0,1)  
(0,1) to [R=$2k\Omega$] (0,-1.5) 
(-3,1) to [R=$2k\Omega$] (-3,-1.5) 
(-6,-1.5) to [short] (-3,-1.5) 
(-3,-1.5) to [short] (0,-1.5) 
(-3,-1.5) -- (-3,-1.7) node[ground]{}
; 

%Segundo circuito 

\draw (4,-1.5) 
to [V, v=$V_i$,invert] (4,3) 
to [short] (7,3)  
to [diode] (7,1)   
(7,3) to [short] (10,3) 
to [R=$1k\Omega$] (10,1)  
(7,1) to [diode] (10,1)  
(10,1) to [R=$2k\Omega$, v] (10,-1.5) 
(7,1) to [R=$2k\Omega$] (7,-1.5) 
(4,-1.5) to [short] (7,-1.5) 
(7,-1.5) to [short] (10,-1.5) 
(7,-1.5) -- (7,-1.7) node[ground]{}

;

\end{circuitikz} 
\end{document}

I would like to look more like this doc:

enter image description here

Appreciate the help!

1
  • \noindent and [scale=0.6] would help. I would put each circuit into a separate circuitikz and use things like \hfill to move them around. Dec 30, 2019 at 16:36

2 Answers 2

4

I understand, that you like to have two circuit schemes in parallel:

enter image description here

(red lines indicate text area borders)

This is simple to obtain with use relative coordinates in circuits drawing. In such approach you only need to determine starting point, from where you draw your circuits. I the following schemes is also used siunitx notation for units:

\documentclass{article}
\usepackage{geometry}
\usepackage[siunitx, american]{circuitikz}
\usetikzlibrary{arrows, shapes}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{center}
    \begin{circuitikz}
%Primer circuito
\draw   (0,0)   coordinate (A)
                to [V=$V_i$,invert] ++ (0, 6)
                to [short]          ++ (2, 0) coordinate (aux1)
                to [diode]          ++ (0,-3) coordinate (aux2)
                to [R=2<\kilo\ohm>]      ++ (0,-3) node[ground]{}
                to [short]  (A)
        (aux1)  to [short]          ++ (2,0)
                to [battery,l=1<\volt>] ++ (0,-3)
                to [R=2<\kilo\ohm>] ++ (0,-3)
                to [short]          ++ (-2,0)
        (aux2)  to [R=1<\kilo\ohm>,v=$V_0$] ++ (2,0)
        ;

%Segundo circuito
\draw   (A) ++ (8,0) coordinate (B) % here is determined starting point of the second circuit
                to [V=$V_i$,invert] ++ (0, 6)
                to [short]          ++ (2, 0) coordinate (aux1)
                to [diode]          ++ (0,-3) coordinate (aux2)
                to [R=2<\kilo\ohm>]      ++ (0,-3) node[ground]{}
                to [short]  (B)
        (aux1)  to [short]          ++ (2,0)
                to [R=1<\kilo\ohm>] ++ (0,-3)
                to [R=2<\kilo\ohm>, v=$V_o$] ++ (0,-3)
                to [short]          ++ (-2,0)
        (aux2)  to [diode] ++ (2,0)
        ;
    \end{circuitikz}
\end{center}
\end{document}

EDIT: Added missing elements of labels in the first example, and added new example, where lines connections are marked with dots.

\documentclass{article}
\usepackage{geometry}
\usepackage[siunitx, american]{circuitikz}
\usetikzlibrary{arrows, shapes}

\begin{document}
\begin{center}
    \begin{circuitikz}
%Primer circuito
\draw   (0,0)   coordinate (A)
                to [V=$V_i$,invert] ++ (0, 6)
                to [short,-*]       ++ (2, 0) coordinate (aux1)
                to [diode,-*]       ++ (0,-3) coordinate (aux2)
                to [R=2<\kilo\ohm>,-*]      ++ (0,-3) node[ground]{}
                to [short]  (A)
        (aux1)  to [short]          ++ (2,0)
                to [battery,l=1<\volt>,-*] ++ (0,-3)
                to [R=2<\kilo\ohm>] ++ (0,-3)
                to [short]          ++ (-2,0)
        (aux2)  to [R=1<\kilo\ohm>,v=$V_0$] ++ (2,0)
        ;

%Segundo circuito
\draw   (A) ++ (8,0) coordinate (B) % here is determined starting point of the second circuit
                to [V=$V_i$,invert] ++ (0, 6)
                to [short,-*]       ++ (2, 0) coordinate (aux1)
                to [diode,-*]       ++ (0,-3) coordinate (aux2)
                to [R=2<\kilo\ohm>,-*]      ++ (0,-3) node[ground]{}
                to [short]  (B)
        (aux1)  to [short]          ++ (2,0)
                to [R=1<\kilo\ohm>] ++ (0,-3)
                to [R=2<\kilo\ohm>, v=$V_o$] ++ (0,-3)
                to [short]          ++ (-2,0)
        (aux2)  to [diode,-*] ++ (2,0)
        ;
    \end{circuitikz}
\end{center}
\end{document}

enter image description here

Edit 2 corrected disorder in example sequence: the second example is not nested in the first anymore.

4
  • Nice, but the node at the four-wire crossing should be there... in this case is not optional. +1.
    – Rmano
    Dec 30, 2019 at 14:22
  • @Rmano, see edited answer. Do you mean that "dots" in junction should be added?
    – Zarko
    Dec 30, 2019 at 14:57
  • Yes --- but the only one really needed is the one on the ground symbol, because in that case it's not clear if you have a connection or not without the dot. The other ones is just a matter of style and personal preferences. Thanks! You can have a circuitikz hat too!
    – Rmano
    Dec 30, 2019 at 15:24
  • 1
    @Rmano, you are right. Here is four wires connected .. i didn't observe this before :-(
    – Zarko
    Dec 30, 2019 at 15:43
4

In TikZ (and circuitikz is based on TikZ) you can move anything by saying

\begin{scope}[xshift=<some x shift>,xshift=<some x shift>]
 <contents>
\end{scope}

or

\begin{scope}[shift={(<delta x>,<delta y>)}]
 <contents>
\end{scope}

so

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage[american]{circuitikz} 
\usetikzlibrary{arrows}  
\begin{document} 
\begin{circuitikz}   

 %Primer circuito
 \draw (-6,-1.5) 
 to [V, v=$V_i$,invert] (-6,3)
 to [short] (-3,3)  
 to [diode] (-3,1)   
 (-3,3) to [short] (0,3) 
 to [battery, label = 1V] (0,1)  
 (-3,1) to [R=$1k\Omega $,v = $V_o$] (0,1)  
 (0,1) to [R=$2k\Omega$] (0,-1.5) 
 (-3,1) to [R=$2k\Omega$] (-3,-1.5) 
 (-6,-1.5) to [short] (-3,-1.5) 
 (-3,-1.5) to [short] (0,-1.5) 
 (-3,-1.5) -- (-3,-1.7) node[ground]{}
 ; 

 \begin{scope}[xshift=-10cm,yshift=-6cm]
 %Segundo circuito 

  \draw (4,-1.5) 
  to [V, v=$V_i$,invert] (4,3) 
  to [short] (7,3)  
  to [diode] (7,1)   
  (7,3) to [short] (10,3) 
  to [R=$1k\Omega$] (10,1)  
  (7,1) to [diode] (10,1)  
  (10,1) to [R=$2k\Omega$, v] (10,-1.5) 
  (7,1) to [R=$2k\Omega$] (7,-1.5) 
  (4,-1.5) to [short] (7,-1.5) 
  (7,-1.5) to [short] (10,-1.5) 
  (7,-1.5) -- (7,-1.7) node[ground]{}
  ;
 \end{scope}
\end{circuitikz} 
\end{document}

enter image description here

Please note that you could avoid much of this by changing your approach. I am not going to discuss all possible improvements. Rather, I will focus on the TikZ-specific ones and units. I also won't change the arrows library since you seem to be happy with what it gives you. However, I'd lie to advertise

  1. relative positioning, and
  2. siunitx.

With these the code becomes

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage[american]{circuitikz} 
\usepackage{siunitx}
\usetikzlibrary{arrows}  
\begin{document} 
\begin{circuitikz}   
 %Primer circuito
 \draw (-6,-1.5) 
 to [V, v=$V_i$,invert] ++ (0,4.5)
 to [short] ++ (3,0)  
 to [diode] ++ (0,-2)   
 ++ (0,2) to [short] ++(3,0) 
 to [battery, label =\SI{1}{\volt}] ++(0,-2)
 ++(-3,0) to [R=\SI{1}{\kilo\ohm},v = $V_o$] ++(3,0)
     to [R=\SI{2}{\kilo\ohm}] ++(0,-2.5) 
 ++(-3,2.5) to [R=\SI{2}{\kilo\ohm}] ++(0,-2.5) 
 ++(-3,0) to [short] ++(3,0)  to [short] ++(3,0) 
 ++(-3,0) -- ++(0,-0.2) node[ground]{}; 

  \draw (-6,-8.5) 
  to [V, v=$V_i$,invert] ++(0,4.5)
  to [short] ++(3,0)
  to [diode] ++(0,-2)
  ++(0,2) to [short]  ++(3,0)
  to [R=\SI{1}{\kilo\ohm}] ++(0,-2)
   ++(-3,0) to [diode] ++(3,0)
     to [R=\SI{2}{\kilo\ohm}, v] ++(0,-2.5) 
  ++(-3,2.5) to [R=\SI{2}{\kilo\ohm}] ++(0,-2.5) 
  ++(-3,0) to [short] ++(3,0) 
     to [short] ++(3,0) 
  ++(-3,0)  -- ++(0,-0.2) node[ground]{};
\end{circuitikz} 
\end{document}

As you see moving the circuit it even simpler since all coordinates are relative to the first one. I find them more intuitive, too. And with siunitx you achieve consistent typesetting of the units.

3
  • This should give you a circuitikz hat! Thanks and my +1! But please add a node at the four-wire crossing near the ground... in this case it's not optional.
    – Rmano
    Dec 30, 2019 at 14:21
  • @Rmano Thanks! I must confess that I do not really understand what you want me to do. The OP seems to have very different target outputs in which there are no crossings, see here. All this answer is saying is how one can move these things around, and makes the suggestion to switch to relative coordinates (which has been copied in the answer below, of course without mentioning this answer...). If I edit this now, the usual thing will happen, some suggestion that I copied and from the other answer, and I do not want to go there.
    – user194703
    Dec 30, 2019 at 16:37
  • I am sorry if I wasn't clear. As I said in the comments to the other answer, if you have a crossing with three wires there is no doubt that they are connected. On the other hand, a four-side crossing, like the one just above the ground symbol here, can be interpreted as two wires with or without electric connection, so you need to put a dot is what you intended is a connection. The OP solves the problem by replicating the ground symbol and avoiding the 4-side crossing... I am not sure if I explained myself correctly, sorry...
    – Rmano
    Dec 30, 2019 at 22:41

You must log in to answer this question.

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