如何向 circuitikz 添加组件?

如何向 circuitikz 添加组件?

如同CircuiTikZ — 创建新组件


我正在使用 circuitikz 创建电路图。我发现齐纳二极管的预设符号与我希望用来表示齐纳二极管的符号不同。


我已经构建了以下代码来tikz显示我想要使用的符号。

我的问题是,我如何将其存储为组件,以便使用[nzD]预设符号进行调用,以便它在电路中工作。


\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{5mm}
\usepackage{tikz}
\usepackage{circuitikz}

\title{New Zener Diode}

\begin{document}

    \begin{preview}
    \centering
        \begin{circuitikz}

            \draw        (0,0)  --(0.22,0)  to  [open]  (0.78,0)--      (1,0)   ;       % connecting wires          
            \draw [thick](0.22,0)--(0.22,0.35)--(0.78,0)--(0.22,-0.35)--(0.22,0)            % triangle      
                         (0.84,0.35)--(0.78,0.35)--(0.78,-0.35)--(0.72,-0.35)   ;       % vertical

            %\draw       (0,0)              to [zD]                     (1,0)   ;       % preset zener diode

        \end{circuitikz}        
    \end{preview}
\end{document}  

答案1

该文件circuitikz1.code.tex包含齐纳二极管zD及其变体的所有样式定义zD*以及zDo长形式Zener diodeempty Zener diodefull Zener diode
zDZener diode样式分别根据样式/选项empty diodes/emptydiodesfull diodes/动态切换为空二极管或满二极管fulldiodes。)

这些样式被复制以构成new齐纳二极管系列。由于我们想在路径上使用此形状,因此我们还需要定义一组paths。这些只是从旧的齐纳二极管系列复制而来,并进行了调整以匹配新形状。

实际的形状重新定义发生在\pgfcircledeclarebipole宏中。同样,这些定义是从pgfcircbipoles.sty文件中复制的:名称已更改(我添加了n)。

第一条路径是三角形的路径,第二条路径是它前面的线条的路径。

\pgfpathmoveto{\pgfpoint{\pgf@circ@[email protected]\pgf@circ@res@left}{\pgf@circ@res@down}}

.8注意到此行中的附加内容了\pgfpathmoveto吗? 就是这样!

代码

\documentclass[tikz]{standalone}
\usepackage{circuitikz}
\makeatletter
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/diode/height}}{emptynzdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfscope
        \pgftransformxshift{\pgf@circ@res@left}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@[email protected]\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@[email protected]\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/diode/height}}{fullnzdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfscope
        \pgftransformxshift{\pgf@circ@res@left}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
        \pgfusepath{draw,fill}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@[email protected]\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@[email protected]\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}
\tikzset{
    nzD/.style={new Zener diode},
    nzD*/.style={full new Zener diode},
    nzDo/.style={empty new Zener diode},
    new Zener diode/.style={\ifpgf@circuit@fulldiode full \else empty \fi new Zener diode},
    full new Zener diode/.style={\circuitikzbasekey, /tikz/to path=\pgf@circ@fullnzdiode@path},
    empty new Zener diode/.style={\circuitikzbasekey, /tikz/to path=\pgf@circ@emptynzdiode@path},
}
\def\pgf@circ@fullnzdiode@path#1{\pgf@circ@bipole@path{fullnzdiode}{#1}}
\def\pgf@circ@emptynzdiode@path#1{\pgf@circ@bipole@path{emptynzdiode}{#1}}
\makeatother
\begin{document}
\begin{circuitikz}
\foreach \diode[count=\x from 0] in {zD,
                    zD*,
                    zDo,
                    nzD,
                    nzD*,
                    nzDo} {
    \draw[yshift=-\x cm] (0,0) to[\diode] (1,0) node[right] {\diode};
}
\end{circuitikz}
\end{document}

输出

在此处输入图片描述

相关内容