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}
Best Answer
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 the0.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 withstraightvoltages
and the open component, that I fixed setting its shift to zero in the third example.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...
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
edge
s 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.