4

I am including circuits drawn with the circuitikz package inside a coloured mdframed environment. I am struggling as I would like to have coloured logic gates. For instance, in the MWE below I'd like the AND gate to be have a white-color filled style.

\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}

enter image description here

1 Answer 1

2

Basically this is the same as here except this doesn't modify the sty file. Note that you must now explicitly draw the node.

\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}

demo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .