4

How to define a specific electrical impedance symbol in Circuitikz: a rectangle filled with diagonal red lines at equal intervals? See the desired output below.

My Desired Output:

enter image description here

My Current Output:

enter image description here

My Current Code:

\documentclass{article}

\usepackage{circuitikz}

\begin{document}

        \begin{circuitikz}[european]

            \draw (0,0) to[R=$R$](0,5);

        \end{circuitikz}

\end{document}
2
  • 2
    Should all R look that way or to you want a separate one? Commented 17 hours ago
  • hello, i would like a separate symbol. thx and best regards Commented 17 hours ago

2 Answers 2

9

I'm assuming the lines should rotate with the shape which is why I'm not using a pattern here (which could also be rotated but then we would have to smuggle the orientation into the shape's definition or use a shape and another drawing which I don't know how to approach in Circuitikz).

Here, is a definition that draws the lines manually

The angle as well as the color can be set via keys, the distance between the lines is fixes.

Code

\documentclass[varwidth]{standalone}
\usepackage{circuitikz}
\makeatletter
\ctikzset{
  bipoles/sssgeneric/angle/.initial=60,
  bipoles/sssgeneric/color/.initial=red,
}
\pgfcircdeclarebipolescaled{resistors}
  {}
  {\ctikzvalof{bipoles/generic/height}}
  {sssgeneric}
  {\ctikzvalof{bipoles/generic/height}}
  {\ctikzvalof{bipoles/generic/width}}
  {%
    \pgfscope
      \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
                              {\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
      \pgfusepathqclip
      \pgf@relevantforpicturesizefalse
      \pgfmathsetlengthmacro\@@ctikz@x{%
        (\pgf@circ@res@up-\pgf@circ@res@down)/
        tan(\pgfkeysvalueof{\circuitikzbasekey/bipoles/sssgeneric/angle})}
      \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{.5*\pgf@circ@res@up+.5*\pgf@circ@res@down}}
      \pgfpathlineto{%
        \pgfpoint{\pgf@circ@res@left+.5*\@@ctikz@x}{\pgf@circ@res@up}}
      \pgfmathtruncatemacro\@@ctikz@xx{(\pgf@circ@res@right-\pgf@circ@res@left)/\@@ctikz@x}
      \foreach \x in {0, 1, ..., \@@ctikz@xx}{
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left+\x.5*\@@ctikz@x}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+(1+\x.5)*\@@ctikz@x}{\pgf@circ@res@up}}}
      \pgfsetstrokecolor{\pgfkeysvalueof{\circuitikzbasekey/bipoles/sssgeneric/color}}
      \pgfusepath{draw}
    \endpgfscope
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
                            {\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@draworfill
  }
\pgfcirc@activate@bipole@simple{l}{sssgeneric}
\pgfcirc@activate@bipole@simple{sssgeneric}{Z}
\makeatother

\begin{document}
\begin{circuitikz}[european]
\foreach \ang in {0, 30, ..., 359}
  \draw (0,0) to[Z=$Z$](\ang:5);
\end{circuitikz}
\end{document}

Output

enter image description here

5
  • 2
    Yes, nicer than mine (and it fits better in).
    – Rmano
    Commented 13 hours ago
  • this is another level :) thanks a lot Commented 12 hours ago
  • The orientation of the shape is given by \pgf@circ@direction. See tex.stackexchange.com/questions/176296/… Commented 10 hours ago
  • @JohnKormylo Interesting, I was already thinking about calculating it with PGF instead of the suggestion in my post but that would make it even easier to use a proper pattern. Just add \pgf@circ@direction to the needed pattern angle. (Though, the pattern will still be at different places in relation to the rectangle.) Commented 10 hours ago
  • @JohnKormylo The only problem could be that \pgf@circ@direction is meaningful only if the shape is used in a to[...] operation. If you want to use, say, node[sssgenericshape, ...] the value could be undefined (or random).
    – Rmano
    Commented 9 hours ago
8

You can copy from pgfcircbipoles.tex the component (in this case, it is generic, which is used for the European-style resistor), and add a pattern.

\documentclass{article}
\usepackage{circuitikz}
\usetikzlibrary{patterns.meta, patterns}
\makeatletter
\pgfcircdeclarebipolescaled{resistors}
{}
{\ctikzvalof{bipoles/generic/height}}
{stripedgeneric}
{\ctikzvalof{bipoles/generic/height}}
{\ctikzvalof{bipoles/generic/width}}
{
    % \pgf@circ@debug@colors
    \pgfsetfillpattern{north east lines}{red}
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfusepath{draw, fill}
}
\pgfcirc@activate@bipole@simple{l}{stripedgeneric}
\makeatother

\begin{document}

\begin{circuitikz}[european]
    \draw (0,0) to[stripedgeneric=$R$] (0,5);
\end{circuitikz}

\end{document}

enter image description here

2
  • 1
    thanks for your effort Commented 12 hours ago
  • @MarcoMoldenhauer you're welcome!
    – Rmano
    Commented 9 hours ago

You must log in to answer this question.

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