2

This question is related to this question but I could not get the satisfactory output. My MWE is given below:

\documentclass[border=3mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\usepackage[american voltages, american currents, siunitx]{circuitikz}

%%% Independent voltage source - American style
%\makeatletter
%\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/vsourceam/height}}{vsourceAM}{\ctikzvalof{bipoles/vsourceam/height}}{\ctikzvalof{bipoles/vsourceam/width}}{%
%   \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
%    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
%    \pgfusepath{draw}
%    \pgfscope
%        \pgftransformxshift{\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@left}
%        \pgftext[rotate=-\pgf@circ@direction]{$-$}
%        \pgfusepath{draw}
%    \endpgfscope
%    \pgfscope
%        \pgftransformxshift{\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@right}
%        \pgftext[rotate=-\pgf@circ@direction]{$+$}
%        \pgfusepath{draw}
%    \endpgfscope
%}
%\makeatother
%
%%% Controlled voltage source - American
%
%\makeatletter
%\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/cvsourceam/height}}{cvsourceAM}{\ctikzvalof{bipoles/cvsourceam/height}}{\ctikzvalof{bipoles/cvsourceam/width}}{
%
%    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
%
%      \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
%        \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
%        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
%        \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
%        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
%        %\pgftext[bottom,rotate=90,y=\ctikzvalof{bipoles/cvsourceam/margin}\pgf@circ@res@left]{$+$}
%        %\pgftext[top,rotate=90,y=\ctikzvalof{bipoles/cvsourceam/margin}\pgf@circ@res@right]{$-$}
%        \pgfusepath{draw}
%    \pgfscope
%        \pgftransformxshift{\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@left}
%        \pgftext[rotate=-\pgf@circ@direction]{$-$}
%        \pgfusepath{draw}
%    \endpgfscope
%    \pgfscope
%        \pgftransformxshift{\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@right}
%        \pgftext[rotate=-\pgf@circ@direction]{$+$}
%        \pgfusepath{draw}
%    \endpgfscope
%}
%\makeatother

\begin{document}
\begin{tikzpicture}[x=3.22cm,y=3.22cm]
\node[](a)at(0,0){};
\draw ($(a)+(0.0,0.0)$) node[circ]{}  to [V, l=1<\volt>] ($(a)+(0.0,1.0)$) node[circ]{} 
    to [V, l_=2<\volt>] ($(a)+(1.0,1.0)$) node[circ]{};
\end{tikzpicture}
\end{document}

Output of the code is shown below in which we see that the negative polarity of 2V source is vertically marked instead of horizontal mark:

output of the original code

Now, if we uncomment the codes provided in the answer of the aforementioned question, we get the output which is not properly displayed as

output of the modified code

Is there a way to get the output like this with proper orientation of the negative polarity? desired output

1

Doesn't this just amount to switching + and - in the code that you commented out, and to perhaps reduce the shifts?

\documentclass[border=3mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\usepackage[american voltages, american currents, siunitx]{circuitikz}

%% Independent voltage source - American style
\makeatletter
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/vsourceam/height}}{vsourceAM}{\ctikzvalof{bipoles/vsourceam/height}}{\ctikzvalof{bipoles/vsourceam/width}}{%
  \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
   \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
   \pgfusepath{draw}
   \pgfscope
       \pgftransformxshift{0.8*\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@left}
       \pgftext[rotate=-\pgf@circ@direction]{$+$}
       \pgfusepath{draw}
   \endpgfscope
   \pgfscope
       \pgftransformxshift{0.8*\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@right}
       \pgftext[rotate=-\pgf@circ@direction]{$-$}
       \pgfusepath{draw}
   \endpgfscope
}
\makeatother


\begin{document}
\begin{tikzpicture}[x=3.22cm,y=3.22cm]
\node[](a)at(0,0){};
\draw ($(a)+(0.0,0.0)$) node[circ]{}  to [V, l=1<\volt>] ($(a)+(0.0,1.0)$) node[circ]{} 
    to [V, l_=2<\volt>] ($(a)+(1.0,1.0)$) node[circ]{};
\end{tikzpicture}
\end{document}

enter image description here

2
  • sorry it didn't strike in my mind. It works!
    – Khaaba
    Oct 1 '18 at 10:24
  • I have added a follow up question here. Please check and provide me suitable changes
    – Khaaba
    Oct 1 '18 at 16:49

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.