我需要使用不提供的晦涩符号来表示二极管CircuiTikZ
。我设法拼凑了以下内容。
\makeatletter
\pgfcircdeclarebipole{}
{\ctikzvalof{bipoles/diode/height}}
{fauxled}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope
\pgftransformxshift{\pgf@circ@res@left}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
\pgfusepath{draw}
\endpgfscope
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
\pgfpathcircle{\pgfpointorigin}{1.7*\pgf@circ@res@right}
\pgfusepath{draw}
}
\def\pgf@circ@fauxled@path#1{\pgf@circ@bipole@path{fauxled}{#1}}
\compattikzset{faux led/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@fauxled@path}}
\makeatother
这可以完成(创建新CircuiTikZ
组件的faux led
)一阶近似,但是,如果label
将 附加到带有标签的组件上,\draw (0,0) to [faux led, label=LED] (4,0);
则会比理想情况更接近符号。
我怎样才能改变定义组件的标签,以便放置在离符号较远的地方默认情况下?
我没有机会TikZ
经常使用,并且以前从未做过任何低级的东西或用图元绘制任何东西,因此非常欢迎关于如何更好地编写上述组件的一般性评论。
编辑:我在哪里可以找到 的文档pgfcircdeclarebipole
?我显然误解了它的前几个参数的含义。
答案1
这是我想出的一个解决方案。我并不为此感到自豪,但它确实有效。(我希望存在一种更简洁的方法。)我使用的技巧是
- 使用 缩小符号的图形
\pgftransformscale
。这会使符号的边缘远离标签,但也会产生不良效果,即在符号的内部部分(代表二极管的三角形和垂直线)和进入的电路线之间留下间隙。 - 通过在符号内画线来填补这些线中的空隙。
代码:
\makeatletter
\ctikzset{bipoles/faux led/height/.initial=\ctikzvalof{bipoles/diode/height}}
\ctikzset{bipoles/faux led/width/.initial=\ctikzvalof{bipoles/diode/width}}
\pgfcircdeclarebipole{}
{\ctikzvalof{bipoles/faux led/height}}
{fauxled}
{\ctikzvalof{bipoles/faux led/height}}
{\ctikzvalof{bipoles/faux led/width}}
{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope
\pgftransformscale{0.8}
\pgfscope
% triangle
\pgftransformxshift{\pgf@circ@res@left}
% right tip
\pgfpathmoveto{\pgfpoint {\pgf@circ@res@right-\pgf@circ@res@left} {0pt}}
% top left
\pgfpathlineto{\pgfpoint {0pt} {\pgf@circ@res@up }}
% bottom left
\pgfpathlineto{\pgfpoint {0pt} {\pgf@circ@res@down}}
% close path to the right tip
\pgfpathlineto{\pgfpoint {\pgf@circ@res@right-\pgf@circ@res@left} {0pt}}
\endpgfscope
% vertical line
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
% circle
\pgfpathcircle{\pgfpointorigin}{1.9\pgf@circ@res@right}
\pgfusepath{draw}
% complete gaps in circuit wires
\pgfsetlinewidth{.8\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfpathmoveto{\pgfpoint { \pgf@circ@res@right} {0pt}}
\pgfpathlineto{\pgfpoint {1.3\pgf@circ@res@right} {0pt}}
\pgfpathmoveto{\pgfpoint { \pgf@circ@res@left } {0pt}}
\pgfpathlineto{\pgfpoint {1.3\pgf@circ@res@left } {0pt}}
\pgfusepath{draw}
\endpgfscope
}
\def\pgf@circ@fauxled@path#1{\pgf@circ@bipole@path{fauxled}{#1}}
\compattikzset{faux led/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@fauxled@path, label=#1}}
\makeatother
因此,标签和引入电路线的末端似乎都根据符号的大小进行定位。缩小符号可以解决标签的问题,但会导致线路出现新问题。
非常欢迎提出更好的解决方案的建议。