I don't have much experience with creating new symbols using the \pgfdeclareshape macro, and I believe there are a few things I'm overlooking.

My specific question is: Why the line associated with the tikz \draw operation is not obscured by the symbol when placed on a path? For instance, in many examples of the circuits library documentation, resistors are clearly not drawn with a line extending through the center of the symbol.

\pgfdeclareshape{symbol shape}



circuit declare symbol=symbol,
set symbol graphic={shape=symbol shape, draw, minimum size=1cm,transform shape}
\draw (0,0) to [symbol] (8,0);

Can anyone suggest an improvement to the code shown above in order to prevent the \draw operation line from extending through the symbol?


TikZ doesn’t know where the lines should start and end. You haven’t defined a border or any anchors besides the center one.

When we base our shape on rectangle ee we get all the properties of the rectangle shape plus the input and output anchors that are additionally defined for rectangle ee.

The size of the rectangle (2cm x .5cm) is based on \tikzcircuitssizeunit (initially 7pt) via the circuit symbol size style. Now the rectangle scales properly with all other circuit shape options. The resistor’s default setting is width 4 height 1. For the sizes 2cm x .5cm the value is width 8.12936 height 2.03233.

Of course, if the shape should always have the same size you can use minimum width=2cm, minimum height=.5cm.


\pgfdeclareshape{symbol shape}{%
  \inheritsavedanchors[from=rectangle ee]
  \inheritanchor[from=rectangle ee]{center}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}
  \inheritanchorborder[from=rectangle ee]
  \inheritbackgroundpath[from=rectangle ee]
    \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}%
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}%
  circuit declare symbol=symbol,
  set symbol graphic={
    shape=symbol shape,
    transform shape,
    circuit symbol size=width 8.12936 height 2.03233,
%    circuit symbol size=width 4 height 1,% standard value for an resistor
\begin{tikzpicture}[circuit ee IEC]
\draw (0,0) to [symbol] (3,0) to [resistor] (5,0);


enter image description here

  • Thanks very much, this is what I wanted to achieve. Your pointing out that a border is needed makes sense.
    – John Chris
    Jul 2 '13 at 21:41

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.