I realize that a symbol, by design, will have mostly static features. The exceptions are annotations. A particular instance of a symbol may have property values associated with it which are variable between instances. A resistor, for instance, will have the same lines on the background path between instances, but we may indicate different values by a string, property = value unit, placed at a node.
I would like to create a symbol for a resistor-like symbol which has two parts; the body is simply divided into two sections by means of a vertical line. I would, however, like to be able to adjust the relative horizontal position of the vertical line such that the relative widths of the compartments could be varied. I am not aware of a mechanism that would allow one to pass a scale value to the particular instance of the symbol. Maybe the same way we adjust the overall size of the symbol, we can adjust the position of the vertical line/divider.
Code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\usetikzlibrary{circuits,circuits.ee.IEC}
\makeatletter
\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]
\behindbackgroundpath{%
\pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}%
\pgf@xa\pgf@x\pgf@ya\pgf@y
\pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}%
\pgf@xb\pgf@x\pgf@yb\pgf@y
\pgfpathmoveto{\pgfqpoint{\pgf@xa}{0pt}}%
\pgfpathlineto{\pgfqpoint{1.5\pgf@xa}{0pt}}%
\pgfpathmoveto{\pgfqpoint{\pgf@xb}{0pt}}%
\pgfpathlineto{\pgfqpoint{1.5\pgf@xb}{0pt}}%
\pgfpathmoveto{\pgfqpoint{0pt}{\pgf@ya}}%
\pgfpathlineto{\pgfqpoint{0pt}{\pgf@yb}}%
}
}
\makeatother
\tikzset{
circuit declare symbol=symbol,
set symbol graphic={
shape=symbol shape,
draw,
transform shape,
circuit symbol size=width 8.12936 height 2.03233,
}
}
\begin{document}
\begin{tikzpicture}[circuit ee IEC]
\node[symbol] at (0,0) (thesymbol) {};
\end{tikzpicture}
\end{document}
The vertical separating line is currently defined by the code:
\pgfpathmoveto{\pgfqpoint{0pt}{\pgf@ya}}%
\pgfpathlineto{\pgfqpoint{0pt}{\pgf@yb}}%
The x-component/first argument of the \pgfqpoint command is what I'm interested in making variable. Appropriate lower and upper bounds are \pgf@xa and \pgf@xb.
Note that the code here was largely written by forum user Qrrbrbirlbel in an answer to this question.
Any suggestions are welcomed.
\draw (thesymbol.west) -- ++ (-1,1);
. Yes, nit-picking at its best, but then again, I don’t know what you want to do with these shapes but if the lines simply connect tocircuits
’ lines I wouldn’t add those. That said, let me clarify the actual question here: Do you want to give ratio between0
(= vertical line is at the left) and1
(= vertical line is at the right), where.5
would result in the output you (hard-)coded?