Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] voltage shift is not consistent across components #747

Closed
Rmano opened this issue Oct 22, 2023 · 1 comment · Fixed by #750
Closed

[Bug] voltage shift is not consistent across components #747

Rmano opened this issue Oct 22, 2023 · 1 comment · Fixed by #750
Assignees

Comments

@Rmano
Copy link
Collaborator

Rmano commented Oct 22, 2023

Reported on TeX.stackexchange by UserUnkn4wn

When used globally, voltage shift works in different ways for different components.

\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}

image

Notice how the shift in the voltage source and the open arrow is wrong (too much).

@Rmano Rmano self-assigned this Oct 22, 2023
@Rmano
Copy link
Collaborator Author

Rmano commented Oct 24, 2023

There are clearly two issues here: one is the one spotted on TeX.SX, the other one is that there is something going awry with the open voltage positioning (they are interwined with the additional shift and they shouldn't):

\documentclass[border=3mm]{standalone}
\usepackage{graphicx} % Required for inserting images
\usepackage{etoolbox}

\usepackage[european,straightvoltages]{circuitikz}
\makeatletter
\iftrue
\patchcmd{\pgf@circ@drawvoltagegenerator}
    {\pgfmathsetmacro{\bumpaplus}{\bumpa + 0.5*\shiftv}}
    {\pgfmathsetmacro{\bumpaplus}{\bumpa + 0.3*\shiftv}}
    {\relax}{\ERROR}
\fi
\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}{%
    \begin{circuitikz}[scale=2]
        % 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}
}

\begin{document}

\circuit
\quad
\ctikzset{voltage shift = 2}
\circuit

\end{document}

image

Rmano added a commit to Rmano/circuitikz that referenced this issue Oct 29, 2023
As you can see in issue circuitikz#747, the `voltage shift` factor is not
always coherent when applied to normal bipoles and sources, especially
if the standard size of the component is different.
Changing the positioning of the voltage elements maintaining backward
compatibility is too difficult for a minor review.
Added a tunable to adjust the amount added for sources.

Fixes circuitikz#747
Rmano added a commit to Rmano/circuitikz that referenced this issue Oct 29, 2023
This version features an important overhaul of the `muxdemux`
configurable component/shape, making it much more flexible and powerful
by adding configurable labels and negation and clock symbols to the
pins.
Also, a couple of minor fixes/workarounds.

- Added optional and configurable inner, outer and border labels to the
  `muxdemux` shapes
- Added optional clock wedge and negation signs to the pins of
  `muxdemux` shapes
- Added the possibility to add a background drawing to `muxdemux` shapes
- Fixed a [bug](circuitikz#748)
  with `straightvoltages` and `open`
- Added an (ugly) workaround for a [voltage shift
  mismatch](circuitikz#747) for
  sources
Rmano added a commit that referenced this issue Oct 29, 2023
CTAN version 1.6.5 (2023-10-29)

This version features an important overhaul of the `muxdemux` configurable component/shape, making it much more flexible and powerful by adding configurable labels and negation and clock symbols to the pins.
Also, a couple of minor fixes/workarounds.

- Added optional and configurable inner, outer and border labels to the `muxdemux` shapes
- Added optional clock wedge and negation signs to the pins of `muxdemux` shapes
- Added the possibility to add a background drawing to `muxdemux` shapes
- Fixed a [bug](#748) with `straightvoltages` and `open`
- Added an (ugly) workaround for a [voltage shift mismatch](#747) for sources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant