如何在新的 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}

輸出

相關內容