TikZ:控制新电路符号问题

TikZ:控制新电路符号问题

我为电池源 (var battery) 创建了一个新的电路符号。有两个问题和一个疑问:

  1. 我希望减号始终是水平的。
  2. 我想控制加号和减号的方向(例如加号向上或加号向下)。
  3. 是否可以用文本符号更改 + 和 - 的图形表示?

问候,马可

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

答案1

这是一个解决方案。它使用\pgftransformresetnontranslation来确保减号以正确的方式排版,然后将新的缩放因子设置为 的倍数\tikzcircuitssizeunit,以确保符号根据<size> circuit symbols样式缩放。

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

在此处输入图片描述

相关内容