2

How can you specify a fill color for logic gates in circuitikz? It does not work as I would have expected:

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

The output still shows a transparent gate instead of a red one:

transparent gate

  • You should write a feature request to the maintainer of this package. As this would need redefinition of all the ports, it is maybe better do ask the author for such thing. – LaRiFaRi Jul 6 '14 at 22:21
  • The short answer is "no." Have you tried mixing tikz circuit components with circuitikz? I've never had a problem (except for the default size difference). – John Kormylo Jul 7 '14 at 3:14
  • @JohnKormylo I'll have a look at the shapes.gates.logic.US library, although the gates don't look as nice as the ones from circuitikz, in my opinion. – ph4nt0m Jul 7 '14 at 17:19
2

The problem is that pgfcirctripoles.sty defines the path of the shape and then draws it independently of your options, instead of just declaring the path and not using it.

If you modify the definition of the or ports in line 498 of pgfcirctripoles.sty as follows:

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

(which is exactly as before minus few commented lines) you obtain that:

  1. the shape obeys the fill style
  2. you need to put an explicit draw style in the node of the port (i.e. (0,2) node[or port,fill=red,draw] (myor) {})
  • With this modification you will not be able to use it in the to-style form. – John Kormylo Jul 7 '14 at 3:11
  • @JohnKormylo How would you use the to-style form with tripoles? The manual always uses nodes with these, which makes sense since you need to refer to their anchors to connect them to the rest of the circuit... – Bordaigorl Jul 7 '14 at 8:18
  • Some tripoles (such as transistors) can be treated like bipoles with an extra pin. But you are right, or gates are not like that. Never mind. – John Kormylo Jul 7 '14 at 15:21
  • 1
    Personaly, I would have created a new component replacing draw with fill, and named it "or art". – John Kormylo Jul 7 '14 at 15:24
  • Sure that would be nice but would require a lot more code as you would need to define all the related styles...I'm just giving a hint here as to where the problem lays (I'm not circuitikz expert!) – Bordaigorl Jul 7 '14 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.