3

Im currently trying to change the distance between the components and the voltage arrow. But im running into problems.

Without shift is the left circuit. With shift is the right one.

It seems that the voltage shift commands applys relativ to every component, but i dont understand in what way. Every component seems to be the same size as the other component, so i cannot be relativ to their size. It may be relativ to their initial distance?

Is there a way to set the voltage shift to be an absolut value. Or is there a way to apply the voltage shift command to every single component type? I could use this:

\draw (2,0) to [R,v=$U_R$, voltage shift = 2] (2,-1)

But i want to change it globally.

MWE:

\documentclass{report}
\usepackage{graphicx} % Required for inserting images

\usepackage{tikz} \usepackage[european,straightvoltages]{circuitikz}

\ctikzset{resistors/scale=0.55} \ctikzset{inductors/scale=0.55} \ctikzset{capacitors/scale=0.6} \ctikzset{sources/scale=.8} \ctikzset{bipoles/thickness=1} \ctikzset{tripoles/thickness=1} \tikzset{every picture/.style = {transform shape, line width=1pt}}

\begin{document}

\hbox{ \begin{circuitikz} % Switch \draw (2,0) node[spdt, rotate=90,anchor=in] (sw) {}; \draw (sw.out 2) node[right] {(2)}; \draw (sw.out 1) node[left] {(1)};

 %Komponenen
\draw (0.5,0)  to [V_=$U$] (0.5,-1);
\draw (2,0) to [R,v=$U_R$] (2,-1) to [L,v=$U_L$] (2,-2);
\draw (3.5,0) to [C,v=$U_C$] (3.5,-2);

 %Verkabelung
\draw (0.5,0) to (0.5,1.5) -| (sw.out 1);
\draw (3.5,0) to (3.5,1.5) -| (sw.out 2);
\draw (2,-2) to (2,-2.5) -| (0.5,-1);
\draw (3.5,-2) |- (2,-2.5) node[circ]{};

\draw (4.5,1) [open,v=$U$] to (4.5,-2);

\end{circuitikz}

\hspace{2cm}

\ctikzset{voltage shift = 2}
\begin{circuitikz}
% Switch
\draw (2,0) node[spdt, rotate=90,anchor=in] (sw) {};
\draw (sw.out 2)  node[right] {(2)};
\draw (sw.out 1)  node[left] {(1)};

%Komponenen
\draw (0.5,0)  to [V_=$U$] (0.5,-1);
\draw (2,0) to [R,v=$U_R$] (2,-1) to [L,v=$U_L$] (2,-2);
\draw (3.5,0) to [C,v=$U_C$] (3.5,-2);

 %Verkabelung  
\draw (0.5,0) to (0.5,1.5) -| (sw.out 1);
\draw (3.5,0) to (3.5,1.5) -| (sw.out 2);
\draw (2,-2) to (2,-2.5) -| (0.5,-1);
\draw (3.5,-2) |- (2,-2.5) node[circ]{};

\draw (4.5,1) [open,v=$U$] to (4.5,-2);

\end{circuitikz}

}

\end{document}

enter image description here

  • 1
    Different componants use different (ad hoc) formulae incolving voltage/bumb a, voltage/bump b , voltage/european label distance, voltage/distance from line and probably others. Mostly the shift is added (default units are pt), but in at least one case it was multiplied by another distance (bug?). – John Kormylo Oct 21 '23 at 18:41
  • \ctikzset{voltage/distance from line = .2} works very good and creates an very consistent look, thank you. But for some reason dont apply for the voltage source. Maybe because it is not the same label as for the resistors etc. . But im figuring it out. – UserUnkn4wn Oct 21 '23 at 19:34
  • 1
    Hmmm. Yes, voltage and current sources are treated differently, and the distance from line seems to be applied non-uniformly. I'll try to look at it as soon as I can. Anyway, the distances in circuitikz are tuned for \ctikzset{bipoles/length=1.4cm} and the standard scales. So I'll really try to stick with it, and if you want a smaller circuit, use a global scale and transform shape. But yes, probably there is a bug lurking here. – Rmano Oct 21 '23 at 20:56

1 Answers1

3

I checked it, and yes, it's a misfeature or a bug if you want.

The code for the voltage label positioning is very old*, with a lot of magic numbers, and I fear that the straightvoltage option has been tested less than desirable.

I tried some simple changes, but the effect on the backward compatibility is impossible to control. So, changes over there will be a "retirement task", I fear, unless somebody steps in to help...

workaround

Newer versions: Since version 1.6.5, there will be no need to do the patching because I added a tunable to workaround the problem; see https://github.com/circuitikz/circuitikz/pull/750 --- now you just use \ctikzset{voltage shift sources adjust=0.2}

(Up to version 1.6.4): You can tune the effect on the shift for voltage sources with the following code by tuning the 0.2 in the patching code (maybe I'll add this to the stock code, although it is a bit of a brown-paper-bag fix). As you can see, independent from that, there is some pesky things going on with straightvoltages and the open component, that I fixed setting its shift to zero in the third example.

\documentclass[border=3mm]{standalone}
\usepackage{graphicx} % Required for inserting images
\usepackage[european,straightvoltages]{circuitikz}
%%%% hack: tune the 0.2 here to control the voltage source shift
%%%% the other bug: now the "open component" misbehave, but that's
%%%% another story
\usepackage{etoolbox}
\makeatletter
\patchcmd{\pgf@circ@drawvoltagegenerator}
    {\pgfmathsetmacro{\bumpaplus}{\bumpa + 0.5*\shiftv}}
    {\pgfmathsetmacro{\bumpaplus}{\bumpa + 0.2*\shiftv}}
    {\relax}{\ERROR}
\makeatother
\ctikzset{resistors/scale=0.55}
\ctikzset{inductors/scale=0.55}
\ctikzset{capacitors/scale=0.6}
\ctikzset{sources/scale=.8}
\ctikzset{bipoles/thickness=1}
\ctikzset{tripoles/thickness=1}
\tikzset{every picture/.style = {transform shape, line width=1pt}}

\newcommand{\circuit}[1][]{% \begin{circuitikz} % Switch \draw (2,0) node[spdt, rotate=90,anchor=in] (sw) {}; \draw (sw.out 2) node[right] {(2)}; \draw (sw.out 1) node[left] {(1)}; %Komponenen \draw (0.5,0) to [V_=$U$] (0.5,-1); \draw (2,0) to [R,v=$U_R$] (2,-1) to [L,v=$U_L$] (2,-2); \draw (3.5,0) to [C,v=$U_C$] (3.5,-2); %Verkabelung \draw (0.5,0) to (0.5,1.5) -| (sw.out 1); \draw (3.5,0) to (3.5,1.5) -| (sw.out 2); \draw (2,-2) to (2,-2.5) -| (0.5,-1); \draw (3.5,-2) |- (2,-2.5) node[circ]{}; % \draw (4.5,1) [open,v=$U$,#1] to (4.5,-2); \end{circuitikz} }

\begin{document}

\circuit \quad \ctikzset{voltage shift = 2} \circuit \quad \circuit[voltage shift=0] % explicitly put to zero voltage shift for open

\end{document}

enter image description here

Anyway, my suggestion is to stick with the normal size and proportion, and if you want a smaller circuit, just scale it wholesome. I prepared a small example here to show the effect...

\documentclass{report}
\usepackage[a3paper]{geometry}
\usepackage{graphicx} % Required for inserting images

\usepackage[european,straightvoltages]{circuitikz} \ctikzset{bipoles/thickness=1} \ctikzset{tripoles/thickness=1} \tikzset{every picture/.style = {line width=1pt}}

\newcommand{\circuit}{% \begin{tikzpicture} % Switch \draw (2,0) node[spdt, rotate=90,anchor=in] (sw) {}; \draw (sw.out 2) node[right] {(2)}; \draw (sw.out 1) node[left] {(1)}; %Komponenen \draw (0.5,0) to [V_=$U$] (0.5,-1); \draw (2,0) to [R,v=$U_R$] (2,-1) to [L,v=$U_L$] (2,-2); \draw (3.5,0) to [C,v=$U_C$] (3.5,-2); %Verkabelung \draw (0.5,0) to (0.5,1.5) -| (sw.out 1); \draw (3.5,0) to (3.5,1.5) -| (sw.out 2); \draw (2,-2) to (2,-2.5) -| (0.5,-1); \draw (3.5,-2) |- (2,-2.5) node[circ]{}; % \draw (4.5,1) [open,v=$U$] to (4.5,-2); \end{tikzpicture} } \newcommand{\circuitlarge}[1][]{% \begin{tikzpicture}[#1] % Switch \draw (4,0) node[spdt, rotate=90,anchor=in] (sw) {}; \draw (sw.out 2) node[right] {(2)}; \draw (sw.out 1) node[left] {(1)}; %Komponenen \draw (1,0) to [V_=$U$] (1,-2); \draw (4,0) to [R,v=$U_R$] (4,-2) to [L,v=$U_L$] (4,-4); \draw (7,0) to [C,v=$U_C$] (7,-4); %Verkabelung \draw (1,0) to (1,3) -| (sw.out 1); \draw (7,0) to (7,3) -| (sw.out 2); \draw (4,-4) to (4,-5) -| (1,-2); \draw (7,-4) |- (4,-5) node[circ]{}; % \draw (9,2) [open,v=$U$] to (9,-4); \end{tikzpicture} }

\begin{document} {% \ctikzset{resistors/scale=0.55}% \ctikzset{inductors/scale=0.55}% \ctikzset{capacitors/scale=0.6}% \ctikzset{sources/scale=.8}% \circuit } \quad { \ctikzset{sources/scale=1.2}% \ctikzset{switches/scale=1.8}% \LARGE \circuitlarge[scale=0.55, transform shape] \ctikzset{voltage shift=1.5} \circuitlarge[scale=0.55, transform shape]

}

\end{document}

enter image description here

I opened an issue on the GitHub project and try to tackle it in the future. Really, the voltage thing should be completely rewritten (first of all, to use edges for the arrows so that they can be styled independently from the wires, using more reliable anchors, and so on).


(*) yes, it's mine. Old nevertheless.

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • Thank you very much for all of your work. I originally did the small scaling because i worked with mosfets and instead of scaling them up, i made the poor decision to scale everything down... Quick question: Is the new version already published? I use overleaf as an editor and as for now the new command doesn't exist. Maybe they didn't update the package yet. – UserUnkn4wn Oct 30 '23 at 02:45
  • 1
    @UserUnkn4wn thanks! v1.6.5 has been sent to CTAN yesterday, so it should be available on TeXLive in a couple of days. But overleaf doesn't track that so closely - they update with a slower pace for stability (they have 1.6.3 now). Using the patch code is completely equivalent; otherwise, you can look here: https://tex.stackexchange.com/questions/524328/i-need-to-use-a-different-version-of-circuitikz-how-can-i-do-that – Rmano Oct 30 '23 at 07:01