如何在新的 circuitikz 组件中移动锚点?

如何在新的 circuitikz 组件中移动锚点?

漂亮的 circuitikz 包中缺少一些组件。我尝试在问题答案的帮助下创建这些组件CircuiTikZ — 创建新组件circuitikz 中的新组件。现在我得到了所谓的 norator 的以下结果。正如所见,连接器位于圆圈的中心。我希望它们位于圆圈的左侧和右侧。欢迎提出任何建议。

提前谢谢了

在此处输入图片描述

我的代码是:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{circuitikz}

\makeatletter
% used to process styles for to-path
\def\TikzBipolePath#1#2{\pgf@circ@bipole@path{#1}{#2}}
    % restore size value for bipole definitions
\pgf@circ@Rlen = \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
\makeatother

\newlength{\ResUp}
\newlength{\ResDown}
\newlength{\ResLeft}
\newlength{\ResRight}

% norator
\ctikzset{bipoles/norator/height/.initial=.35}   % box height
\ctikzset{bipoles/norator/width/.initial=.35}    % box width
\pgfcircdeclarebipole{}                           % no extra anchors
{\ctikzvalof{bipoles/norator/height}}
{norator}                                        % component name
{\ctikzvalof{bipoles/norator/height}}
{\ctikzvalof{bipoles/norator/width}}
{                                                 % component symbol drawing ...
  \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
  \pgfextracty{\ResUp}{\northeast}                % coordinates
  \pgfextracty{\ResDown}{\southwest}
  \pgfextractx{\ResLeft}{\southwest}
  \pgfextractx{\ResRight}{\northeast}
  \pgfpathellipse{\pgfpoint{\ResUp}{0}}
        {\pgfpoint{0}{\ResUp}}
        {\pgfpoint{\ResUp}{0}}
  \pgfpathellipse{\pgfpoint{-\ResUp}{0}}
        {\pgfpoint{0}{\ResUp}}
        {\pgfpoint{\ResUp}{0}}
  \pgfusepath{draw}                               % draw it!
}

\def\circlepath#1{\TikzBipolePath{norator}{#1}}
\tikzset{norator/.style = {\circuitikzbasekey, /tikz/to path=\circlepath, l=#1}}

\begin{document}
\begin{circuitikz}[scale=0.75, european resistors]
    \draw
    (0,0) to [short, o-] (1,0)
    to [norator] (2,0)                       % connect the new component
    to [R, -o] (5,0)
    ;

\end{circuitikz}
\end{document}

答案1

好的,经过一些实验,我终于找到了一些解决方案:

在此处输入图片描述

我修改的值是初始高度和宽度,然后是圆心和半径。

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{circuitikz}

\makeatletter
% used to process styles for to-path
\def\TikzBipolePath#1#2{\pgf@circ@bipole@path{#1}{#2}}
    % restore size value for bipole definitions
\pgf@circ@Rlen = \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
\makeatother

\newlength{\ResUp}
\newlength{\ResDown}
\newlength{\ResLeft}
\newlength{\ResRight}

% norator
\ctikzset{bipoles/norator/height/.initial=.5}   % box height
\ctikzset{bipoles/norator/width/.initial=.5}    % box width
\pgfcircdeclarebipole{}                           % no extra anchors
{\ctikzvalof{bipoles/norator/height}}
{norator}                                        % component name
{\ctikzvalof{bipoles/norator/height}}
{\ctikzvalof{bipoles/norator/width}}
{                                                 % component symbol drawing ...
  \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}    \pgfstartlinewidth}
  \pgfextracty{\ResUp}{\northeast}                % coordinates
  \pgfextracty{\ResDown}{\southwest}
  \pgfextractx{\ResLeft}{\southwest}
  \pgfextractx{\ResRight}{\northeast}
  \pgfpathellipse{\pgfpoint{\ResUp/2}{0}}
        {\pgfpoint{0}{\ResUp/2}}
        {\pgfpoint{\ResUp/2}{0}}
  \pgfpathellipse{\pgfpoint{-\ResUp/2}{0}}
        {\pgfpoint{0}{\ResUp/2}}
        {\pgfpoint{\ResUp/2}{0}}
  \pgfusepath{draw}                               % draw it!
}

\def\circlepath#1{\TikzBipolePath{norator}{#1}}
\tikzset{norator/.style = {\circuitikzbasekey, /tikz/to path=\circlepath, l=#1}}


\begin{document}
\begin{circuitikz}[scale=0.75, european resistors]
    \draw
    (0,0) to [short, o-] (1,0)
    to [norator] (2,0)                       % connect the new component
    to [R, -o] (5,0)
    ;

\end{circuitikz}
\end{document}

答案2

PSTricks 解决方案使用pst-circ包裹:

\documentclass{article}

\usepackage{pst-circ}

\begin{document}

\begin{pspicture}[dimen = m](5.5,1)
  \pnodes(0,0.5){A}(1,0.5){B}(2,0.5){C}(3,0.5){D}(5.5,0.5){E}
  \wire[arrows = o-](A)(B)
  \Ucc(B)(C){}
  \Ucc(C)(D){}
  \resistor[arrows = -o](D)(E){}
\end{pspicture}

\end{document}

输出

相关内容