3

I would like to be able to align the mass on the left with those on the right: I tried several possibilities but nothing helped, I cannot align. I can't put the 15kW indication above the resistance on the left either. Thanks for your help

\documentclass[border=1mm]{standalone}

\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[european, straightvoltages]{circuitikz}
\usepackage{siunitx}
\usepackage{tabularx}
\usetikzlibrary{babel}

\begin{document}

\begin{circuitikz}[voltage dir=RP]
\draw (0,2.5) node[en amp](opamp){\texttt{LM358}}
(opamp.up) to[crossing] ++(0,0.5) node[above]{\SI{5}{\volt}}
(opamp.down) node[ground]{}
;
\draw (opamp.-) --++(0,1) -| (opamp.out) to[short] ++(0.5,0) coordinate(Rsortie) to[R, l^=$\SI{1}{\kilo\ohm}$] ++(0,-2) node[ground] (GND){}++(0,-0.5);

\draw (opamp.+) --++(-1,0) coordinate(deuxR) to[R, l_=$\SI{10}{\kilo\ohm}$] ++(0,-2) node[ground] {} (GND -|deuxR);
\draw (deuxR) to[R, l^=$\SI{15}{\kilo\ohm}$] ++(-3.5,0) to[short, -o] ++(-0.5,0) coordinate(depart);

\draw (Rsortie) to[short, -o] ++(1.5,0) coordinate(Vs);
\draw (Vs |- GND) node[ground]{} to[open, v>=$V_s$] (Vs);
\draw (Vs) node[above]{A1};

\draw (depart) node [above] {D11};

\end{circuitikz}


\end{document}
1
  • You can use things like (deuxR |- Rsortie) or (deuxR) -| Rsortie) to align either the left to right or right to left. Jan 2, 2021 at 16:27

2 Answers 2

2

I would draw the circuit in the following way, writing it left-to-right as I feel it's more natural. So, I'll start with

\draw (0,0)  node[above]{D11} to[R=\SI{15}{\kohm}, o-] ++(3,0) coordinate(corner-in)
        to [R=\SI{10}{\kohm}] ++(0,-3) % this -3 will fix the gnd line
        node[tlground](GND){};

enter image description here

Now let's position the opamp and connect it to GND:

\draw (corner-in) -- ++(1,0) node[en amp, anchor=+](opamp){\texttt{LM358}}
        (opamp.down) -- (opamp.down|-GND) node[tlground]{};

enter image description here

Now, I feel that the standard position of the inputs in en amps is a bit cramped. A quick glance at the manual tells me that the solution is \ctikzset{tripoles/en amp/input height=0.45}; I'll put that in the preamble (full code later).

The next step is to close the buffer feedback loop and to add the power supply. I advise against using the crossing thing, but if you want to, a solution could be:

     \draw (opamp.up) to[crossing, name=X] ++(0,1) node[vcc]{\SI{5}{V}};
     \draw (opamp.-) |- (X.center) -| (opamp.out);

Notice how I give a name to the crossing and then use the X.center anchor to draw the line --- so now I can change the ++(0,1) over there and anything will fall back in place. |- and -| are very handy TikZ shortcuts.

enter image description here

Let's finish now the circuit with the load resistance and the indication of the output voltage. At this point I decided to change the tlground for ground to have the little tail, and to move the ground level higher --- notice that this is just a change in one number and a search-and-replace for tlground to ground. The final code is

\documentclass[border=2mm]{standalone}
\usepackage[european, RPvoltages, siunitx, straightvoltages]{circuitikz}
\ctikzset{tripoles/en amp/input height=0.45}
\begin{document}
    \begin{circuitikz}
        \draw (0,0)  node[above]{D11} to[R=\SI{15}{\kohm}, o-] ++(3,0) coordinate(corner-in)
        to [R=\SI{10}{\kohm}] ++(0,-2) % this -2 will fix the gnd line
        node[ground](GND){};
        \draw (corner-in) -- ++(1,0) node[en amp, anchor=+](opamp){\texttt{LM358}}
        (opamp.down) -- (opamp.down|-GND) node[ground]{};
        \draw (opamp.up) to[crossing, name=X] ++(0,1) node[vcc]{\SI{5}{V}};
        \draw (opamp.-) |- (X.center) -| (opamp.out);
        \draw (opamp.out) -- ++(0.5,0) coordinate(rload)
        to[short, -o] ++(1.5,0) coordinate(out) node[above]{A1};
        \draw (rload) to[R=\SI{1}{\kohm}] (rload|-GND) node[ground]{};
        \draw (out) to[open, v^=$V_s$] (out|-GND) node[ground]{};
    \end{circuitikz}
\end{document}

enter image description here

Notice that the last screenshot is done with evince, and the previous ones with okular, which has a strange idea of antialiasinging lines...

And finally, what really got me started with circuitikz, is that now, with a trivial change (just change en amp to op amp, raise a bit the vcc — just one number change again! — and add \ctikzsetstyle{romano} somewhere after loading the package) and you have

enter image description here

And a final note: the only absolute coordinate is the (0,0) at the start. Move this and the circuit will follow; this is great to create duplicates, for example, or to create basic blocks that you can reuse around (I normally create macros for them).

3
  • Thank you for this step by step which allows me to understand well how to use the relative coordinates @Rmano : Why did you say " I advise against using the crossing thing" ?
    – Nicolas
    Jan 4, 2021 at 13:12
  • Thanks for the comment! The standard is to just cross the wires: if there are no dots, it is supposed that there is no electrical contact. The "crossing" shape is used only in very basic courses, and students must learn the standard way...
    – Rmano
    Jan 4, 2021 at 15:53
  • 1
    the diagram used is useful to me within the framework of a training course for colleagues more or less beginner in physics: I am not sure that all have these automatisms!
    – Nicolas
    Jan 4, 2021 at 21:30
1

Something like this?

\documentclass[border=1mm]{standalone}

\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[european, straightvoltages]{circuitikz}
\usepackage{siunitx}
\usepackage{tabularx}
\usetikzlibrary{babel}

\begin{document}

\begin{circuitikz}[voltage dir=RP]
\draw (0,2.5) node[en amp](opamp){\texttt{LM358}}
(opamp.up) to[crossing] ++(0,0.5) node[above]{\SI{5}{\volt}}
(opamp.down) node[ground]{}
;
\draw (opamp.-) --++(0,1) -| (opamp.out) to[short] ++(0.5,0) coordinate(Rsortie) to[R, l^=$\SI{1}{\kilo\ohm}$] ++(0,-2) node[ground] (GND){}++(0,-0.5);

\draw (opamp.+) --++(-1,0) coordinate(deuxR) to[R, l_=$\SI{10}{\kilo\ohm}$] ++(0,-1.66) node[ground] {} (GND -|deuxR);
\draw (deuxR) to[R, l_=$\SI{15}{\kilo\ohm}$] ++(-3.5,0) to[short, -o] ++(-0.5,0) coordinate(depart);

\draw (Rsortie) to[short, -o] ++(1.5,0) coordinate(Vs);
\draw (Vs |- GND) node[ground]{} to[open, v>=$V_s$] (Vs);
\draw (Vs) node[above]{A1};

\draw (depart) node [above] {D11};

\end{circuitikz}

\end{document}

I did not change much your example, I just changed two things.

  1. For the 15 kΩ resistor's label to be above the resistor, I changed l^=$\SI{15}{\kilo\ohm}$ to l_=$\SI{15}{\kilo\ohm}$. This is because the resistor is drawn from right to left, hence the inversion of ^ and _.

  2. For the ground on the left to align vertically with those on the right, I simply changed where the node is placed. Here I just tried different values until it seemed aligned enough, but in general a good way to ensure that things are aligned would be to use absolute coordinates to place objects instead of placing objects relative to others.

1
  • thanks. The problem with an en amp is that the absolute coordinates are note simple : the only solution I have found to have beautiful figures is to use relative coordinates
    – Nicolas
    Jan 2, 2021 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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