来自 circuitikz 的彩色符号

来自 circuitikz 的彩色符号

我将用circuitikz包绘制的电路包含在彩色mdframed环境中。我很纠结,因为我想有彩色的逻辑门。例如,在下面的 MWE 中,我希望 AND 门具有白色填充样式。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{graphs.standard}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[siunitx]{circuitikz}
\begin{document}

\mdfdefinestyle{mystyle}{backgroundcolor=gray!40}

\begin{mdframed}[style=mystyle]
\begin{circuitikz} \draw
(0,0) node[and port] (and) {}
(and.out) node[anchor=west] {AB}
(and.in 1) node[anchor=east] {A}
(and.in 2) node[anchor=east] {B};
\end{circuitikz}
\end{mdframed}

\end{document}

在此处输入图片描述

答案1

基本上这与这里但这不会修改 sty 文件。请注意,您现在必须明确绘制节点。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{graphs.standard}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[siunitx]{circuitikz}

\makeatletter
\pgfcircdeclarelogicport{and}{
    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/input height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/input height}\pgf@circ@res@up}}

    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/input height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@left}
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/input height}\pgf@circ@res@down}}

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

    \pgfusepath{draw}% draw contacts (no fill)

    \pgfsetlinewidth{2\pgflinewidth}
    \pgfpathmoveto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@left}
        {\pgf@circ@res@down}}
    \pgfpathcurveto
        {\pgfpoint{.0\pgf@circ@res@left}{\pgf@circ@res@down}}
        {\pgfpoint
            {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@right}
            {.5\pgf@circ@res@down}}
        {\pgfpoint
            {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@right}
            {0pt}}
    \pgfpathcurveto
        {\pgfpoint
            {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@right}
            {.5\pgf@circ@res@up}}
        {\pgfpoint{.0\pgf@circ@res@left}{\pgf@circ@res@up}}
        {\pgfpoint
            {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@left}
            {\pgf@circ@res@up}} 
    %\pgfusepath{draw}
}
\makeatother

\inheritlogicport{american}{and}% otherwise must use [american and port]

\begin{document}

\mdfdefinestyle{mystyle}{backgroundcolor=gray!40}

\begin{mdframed}[style=mystyle]
\begin{circuitikz} \draw
(0,0) node[and port, draw=black, fill=white] (and) {}
(and.out) node[anchor=west] {AB}
(and.in 1) node[anchor=east] {A}
(and.in 2) node[anchor=east] {B};
\end{circuitikz}
\end{mdframed}

\end{document}

演示

相关内容