如何在 circuitikz 中填充逻辑门?

如何在 circuitikz 中填充逻辑门?

如何fill为 中的逻辑门指定颜色circuitikz?它不能像我预期的那样工作:

\documentclass{standalone}
\usepackage{circuitikz}

\begin{document}
\begin{circuitikz} \draw
(0,2) node[or port, fill=red] (myor) {}

(myor.in 1) node[left =.2cm] (a) {A}
(myor.in 2) node[left =.2cm] (b) {B}
(myor.out)  node[right=.2cm] (c) {C}

(myor.in 1) -- (a)
(myor.in 2) -- (b)
(myor.out)  -- (c);
\end{circuitikz}
\end{document}

输出仍然显示透明门而不是红色门:

透明门

答案1

问题在于pgfcirctripoles.sty定义形状的路径,然后独立于您的选项绘制它,而不是仅仅声明路径而不使用它。

or如果修改第498行的端口定义pgfcirctripoles.sty如下:

\pgfcircdeclarelogicport{or}{


    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/input height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {(\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/port width}-\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/input skip})*\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/input height}\pgf@circ@res@up}}

    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/input height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint
        {(\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/port width}-\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/input skip})*\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/input height}\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/port width}\pgf@circ@res@right}
        {0pt}}  

    %\pgfusepath{draw}
    \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/port width}\pgf@circ@res@right
    %\pgfsetlinewidth{2\pgflinewidth}
    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@up}}
    \pgfpathcurveto
        {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/aaa}\pgf@circ@res@left}{\pgf@circ@res@up}}
        {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/bbb}\pgf@circ@res@left}{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/ccc}\pgf@circ@res@up}}
        {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/bbb}\pgf@circ@res@left}{0pt}}
    \pgfpathcurveto
        {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/bbb}\pgf@circ@res@left}{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/ccc}\pgf@circ@res@down}}
        {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/aaa}\pgf@circ@res@left}{\pgf@circ@res@down}}
        {\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@down}}   

    \pgfpathcurveto
        {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/ddd}\pgf@circ@res@left}{\pgf@circ@res@down}}
        {\pgfpoint{\pgf@circ@res@other}{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/ccc}\pgf@circ@res@down}}
        {\pgfpoint{\pgf@circ@res@other}{0pt}}
    \pgfpathcurveto
        {\pgfpoint{\pgf@circ@res@other}{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/ccc}\pgf@circ@res@up}}
        {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/ddd}\pgf@circ@res@left}{\pgf@circ@res@up}}
        {\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@up}} 
    %\pgfusepath{draw}
}

(与以前完全相同,除了几行注释之外)您将获得:

  1. 形状遵循填充样式
  2. 您需要draw在端口节点中放置一个明确的样式(即(0,2) node[or port,fill=red,draw] (myor) {}

相关内容