Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have created a new circuit symbol for battery source (var battery). There are two problems and one question:

  1. I would like for minus to be always horizontal.
  2. I would like to control how plus and minus are oriented (e.g. plus up or plus down).
  3. Is it possible to change graphical representation of + and - with text symbols?

Regards, Marko

\documentclass[12pt,a4paper]{article}
\input{glava}
\usepackage{tikz}

\begin{document}

\usetikzlibrary{circuits.ee}
\usetikzlibrary{circuits.ee.IEC}

\tikzset{circuit declare symbol = var battery}
\tikzset{set var battery graphic = var battery IEC graphic}
\tikzset{var battery IEC graphic/.style=
  {transform shape, circuit symbol lines, circuit symbol size = width
2.5 height 2.5,
   shape=generic circle IEC, /pgf/generic circle IEC/before
background=
    {\pgfpathcircle{\pgfpoint{0.45pt}{0pt}}{0.1pt}
     \pgfpathcircle{\pgfpoint{-0.45pt}{0pt}}{0.1pt}
     \pgfpathmoveto{\pgfpoint{-1.0pt}{0pt}}
     \pgfpathlineto{\pgfpoint{-0.6pt}{0pt}}
     \pgfpathmoveto{\pgfpoint{1.0pt}{0pt}}
     \pgfpathlineto{\pgfpoint{0.6pt}{0pt}}
     % PLUS SYMBOL
     \pgfpathmoveto{\pgfpoint{-0.45pt}{0.25pt}}
     \pgfpathlineto{\pgfpoint{-0.45pt}{0.65pt}}
     \pgfpathmoveto{\pgfpoint{-0.25pt}{0.45pt}}
     \pgfpathlineto{\pgfpoint{-0.65pt}{0.45pt}}
     % MINUS SYMBOL
     \pgfpathmoveto{\pgfpoint{0.25pt}{0.45pt}}
     \pgfpathlineto{\pgfpoint{0.65pt}{0.45pt}}
     \pgfusepathqstroke}}}

\begin{tikzpicture}[circuit ee IEC,semithick,x=1cm,y=1cm]
\draw (0,0) to [capacitor] (3,0)
to [resistor] (3,2)
to [var battery] (0,2)
to [var battery={info'={$U_3$}}] (0,0);
\end{tikzpicture}

\end{document} 
share|improve this question

1 Answer 1

up vote 3 down vote accepted

Here's one solution. It uses \pgftransformresetnontranslation to make sure the minus is typeset the right way round, and then sets a new scaling factor as a multiple of \tikzcircuitssizeunit, which makes sure the symbol scales according to the <size> circuit symbols style.

\documentclass[12pt,a4paper]{article}
%\input{glava}
\usepackage{tikz}

\begin{document}

\usetikzlibrary{circuits.ee}
\usetikzlibrary{circuits.ee.IEC}

\newif\ifreversepolarity
\tikzoption{reversepolarity}[true]{\reversepolaritytrue}


\tikzset{circuit declare symbol = var battery}
\tikzset{set var battery graphic = var battery IEC graphic}
\tikzset{var battery IEC graphic/.style=
  {transform shape, circuit symbol lines, circuit symbol size = width
2.5 height 2.5,
   shape=generic circle IEC, /pgf/generic circle IEC/before
background=
    {
     \pgfpathcircle{\pgfpoint{0.45pt}{0pt}}{0.1pt}
     \pgfpathcircle{\pgfpoint{-0.45pt}{0pt}}{0.1pt}
     \pgfpathmoveto{\pgfpoint{-1.0pt}{0pt}}
     \pgfpathlineto{\pgfpoint{-0.6pt}{0pt}}
     \pgfpathmoveto{\pgfpoint{1.0pt}{0pt}}
     \pgfpathlineto{\pgfpoint{0.6pt}{0pt}}
     \pgfusepathqstroke
     % PLUS AND MINUS SYMBOL
     \pgfgettransform\savedtransform
     \pgftransformshift{\pgfpoint{0.45pt}{0.45pt}}
     \pgftransformresetnontranslations
     \pgftransformscale{0.075\tikzcircuitssizeunit}
     \pgftext{\bf{\ifreversepolarity$-$\else$+$\fi}}
     \pgfsettransform\savedtransform
     \pgftransformshift{\pgfpoint{-0.45pt}{0.45pt}}
     \pgftransformresetnontranslations
     \pgftransformscale{0.075\tikzcircuitssizeunit}
     \pgftext{\bf{\ifreversepolarity$+$\else$-$\fi}}
     \pgfsettransform\savedtransform
     }}}

\begin{tikzpicture}[circuit ee IEC,semithick,x=1cm,y=1cm]
\draw (0,0) to [capacitor] (3,0)
to [resistor] (3,2)
to [var battery,reversepolarity,tiny circuit symbols] (0,2)
to [var battery={info'={$U_3$}},huge circuit symbols] (0,0);
\end{tikzpicture}

\end{document} 

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.