4

German school books use open circles to mark electrical sources:

 \documentclass[border=3mm]{standalone}
 \usepackage{circuitikz}
 
 \makeatletter
 \pgfcircdeclarebipole{}{\ctikzvalof{bipoles/open/height}}{customV}{\ctikzvalof{bipoles/open/height}}{\ctikzvalof{bipoles/vsource/width}}{
     \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
     \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
     \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
     \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
 }
 \def\pgf@circ@customV@path#1{\pgf@circ@bipole@path{customV}{#1}}
 \compattikzset{customV/.style={\circuitikzbasekey, /tikz/to path=\pgf@circ@customV@path, label=#1}}
 \makeatother
 
 \begin{document}
 \begin{circuitikz}
 \draw (0,0) to[customV] ++(3,0);
 \end{circuitikz}
 \end{document}

enter image description here

This solution I found at Change appearance of voltage source in circuitikz But to be honest, I don't get how the costumV works.

So I would like to ask for two things I additionally need:

  1. In case of direct current, + and - where added above the circles, alternate current through a ~ in the middle top the two circles.
  2. How to control the distance between the circles?

Thanks a lot for any hint :)

2 Answers 2

4

With the new infrastructure of circuitikz you can define your symbol, for example, like this (I borrowed part of Jasper Habicht's answer); that way the new bipole is recognized as a voltage source, and it scales (or changes style) correctly.

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[siunitx, RPvoltages]{circuitikz}
\makeatletter
% use a separate width and height. Notice that the height
% will basically decide at which distance the labels are
% drawn.
\ctikzset{bipoles/germanDCV/height/.initial=.20}
\ctikzset{bipoles/germanDCV/width/.initial=.60}
% put the bipole in the "sources" class, so that it will scale
% with them
\pgfcircdeclarebipolescaled{sources}
{
    % save the name of this node so that we can reference the
    % internal nodes
    \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
}
{\ctikzvalof{bipoles/germanDCV/height}}
{germanDCV}
{\ctikzvalof{bipoles/germanDCV/height}}
{\ctikzvalof{bipoles/germanDCV/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfnode{ocirc}{center}{}{\thisshape-L}{\pgfusepath{draw}}
    % use the ocirc anchor to position the sign, so it will do the right thing
    % if you change "ocirc" dimensions.
    \pgftext[bottom, at=\pgfpointanchor{\thisshape-L}{n}]{\footnotesize $\mathstrut +$}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
    \pgfnode{ocirc}{center}{}{\thisshape-R}{\pgfusepath{draw}}
    \pgftext[bottom, at=\pgfpointanchor{\thisshape-R}{n}]{\footnotesize $\mathstrut -$}
}
% activate the bipole, specifying that it's a voltage, and that the voltage
% symbols are inside and drawn with the symbol. That will work correctly only with
% "american" settings. You can try with european too, in that case use true for the
% is voltageoutsideofsymbol and adjust the height so that the arrow will not overlap.
\pgfcirc@activate@bipole@simple@opt{v}{germanDCV}{\circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=false}
%%%%
%%%% and this is the AC version...
\ctikzset{bipoles/germanACV/height/.initial=.20}
\ctikzset{bipoles/germanACV/width/.initial=.60}
\pgfcircdeclarebipolescaled{sources}
{
    % save the name of this node so that we can reference the
    % internal nodes
    \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
}
{\ctikzvalof{bipoles/germanACV/height}}
{germanACV}
{\ctikzvalof{bipoles/germanACV/height}}
{\ctikzvalof{bipoles/germanACV/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    % play with the coordinate here to move the symbol...
    \pgftext[bottom, at=\pgfpoint{0pt}{0pt}]{\small ${\sim}$}
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfnode{ocirc}{center}{}{\thisshape-L}{\pgfusepath{draw}}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
    \pgfnode{ocirc}{center}{}{\thisshape-R}{\pgfusepath{draw}}
}
% activate the bipole, specifying that it's a voltage, and that the voltage
% symbols are inside and drawn with the symbol. That will work correctly only with
% "american" settings. You can try with european too, in that case use true for the
% is voltageoutsideofsymbol and adjust the height so that the arrow will not overlap.
\pgfcirc@activate@bipole@simple@opt{v}{germanACV}{\circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=false}
\makeatother

\begin{document}
\begin{tikzpicture}[]
    \draw (0,1) to[germanDCV, name=N1] ++(2,0) to[germanDCV, mirror, invert] ++(2,0);
    \draw (0,0) to[american, germanDCV=\SI{3}{V}] ++(2,0)
        to[germanDCV, l_=$V_2$, mirror, invert, name=N2] ++(2,0);
    \draw [thin, red] (N1-R) -- (N2-R); % N2 is inverted
    \draw [color=blue] (0,-1)  to[germanACV, name=N1] ++(2,0)
        to[germanACV, l_=$V_3$] ++(2,0);
\end{tikzpicture}
\end{document}

enter image description here

I think it should be easy to generate the AC one, but I'll add it if requested.

3
  • Thank you, that's it! It would be nice if you could also add the AC one :)
    – Bigga
    May 15, 2023 at 7:01
  • 1
    @Bigga done (I had not time earlier, sorry...)
    – Rmano
    May 24, 2023 at 16:59
  • Thanks. Sorry for the late answer, didn't recognize your comment
    – Bigga
    Feb 19 at 8:18
4

Well, you could actually just use the following code (which is only a slight modification of an example from the manual:

\documentclass[border=3mm]{standalone}
\usepackage{circuitikz}

\begin{document}
\begin{circuitikz}
\draw[american voltages] 
    (0,1.5) -- ++(0.5,0) to[open, v=$\sim$, o-o] ++(2,0) -- ++(0.5,0);
\end{circuitikz}
\end{document}

enter image description here


But if you want to stick to the custom code you found, you could add the current signs as follows:

\documentclass[border=3mm]{standalone}
\usepackage{circuitikz}

\makeatletter
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/open/height}}{customV}{\ctikzvalof{bipoles/open/height}}{\ctikzvalof{bipoles/vsource/width}}{
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@left}{7pt}}
    \pgfnode{rectangle}{center}{\footnotesize $+$}{}{}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
    \pgfnode{rectangle}{center}{\footnotesize $-$}{}{}
}
  \def\pgf@circ@customV@path#1{\pgf@circ@bipole@path{customV}{#1}}
  \compattikzset{customV/.style={\circuitikzbasekey, /tikz/to path=\pgf@circ@customV@path, label=#1}}
\makeatother

\begin{document}
\begin{circuitikz}
\draw (0,0) to[customV] ++(3,0);

\draw (0,-1) to[customV={$\sim$}] ++(3,0);

\draw (0,-2) to[customV={$\sim$}, invert] ++(3,0);

\draw (0,-3) to[customV={$\sim$}, bipoles/vsource/width=1] ++(3,0);

\end{circuitikz}
\end{document}

enter image description here


Note, that (as pointed out in the comments to the original answer already) you can get current signs also using the v option in combination with the american voltages option, but they would not sit on top of the small circles:

\documentclass[border=3mm]{standalone}
\usepackage{circuitikz}

\makeatletter
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/open/height}}{customV}{\ctikzvalof{bipoles/open/height}}{\ctikzvalof{bipoles/vsource/width}}{
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
}
  \def\pgf@circ@customV@path#1{\pgf@circ@bipole@path{customV}{#1}}
  \compattikzset{customV/.style={\circuitikzbasekey, /tikz/to path=\pgf@circ@customV@path, label=#1}}
\makeatother

\begin{document}
\begin{circuitikz}[american voltages]

\draw (0,-1) to[customV, v^={$\sim$}] ++(3,0);

\end{circuitikz}
\end{document}

enter image description here

In general, you can use the option american voltages either on the whole tikzpicture environment, on single \draw macros or you can use the american option on to-paths, such as:

\draw (0,-1) to[american, customV, v^={$\sim$}] ++(3,0);
1
  • Thank you for the solution and your description :)
    – Bigga
    May 15, 2023 at 7:03

You must log in to answer this question.

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