我可以手动绘制一个交流源:
\begin{tikzpicture}
\draw (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);
\draw (2,0) circle (2.5);
\end{tikzpicture}
我如何声明一个ACsource
符号,以便我可以写下以下内容,或者一些类似且更正确的内容:
\draw (0,5) to [ACsource={volt=220}] (5,5);
另外,当我能够将其声明为符号时,它的行为是否已经与库中的其他默认符号相同circuits
?举例来说,它的行为是否会像这样resistor
,在适当的位置绘制连接线和标签?我还希望ACsource
具有适当的大小,以遵循诸如small circuit symbols
、huge circuit symbols
等键。
\draw (0,0) to [resistor={ohm=5}] (5,0);
回应@morbusg回答:
我正在使用 LaTeX。这是我的 MWE:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\tikzset{circuit declare symbol = ac current source}
\tikzset{%
ac current source IEC graphic/.style={%
circuit symbol lines,
circuit symbol size = width 2 height 2,
shape = generic circle IEC,
/pgf/generic circle IEC/before background={%
\pgfpathmoveto{\pgfpoint{-0.8pt}{0pt}}
\pgfpathsine{\pgfpoint{0.4pt}{0.4pt}}
\pgfpathcosine{\pgfpoint{0.4pt}{-0.4pt}}
\pgfpathsine{\pgfpoint{0.4pt}{-0.4pt}}
\pgfpathcosine{\pgfpoint{0.4pt}{0.4pt}}
\pgfusepath{stroke}
},
transform shape
}
}
\tikzset{%
circuit ee IEC/.append style={%
{set ac current source graphic = ac current source IEC graphic}
}
}
\begin{document}
\begin{tikzpicture}[circuit ee IEC]
\draw node [ac current source, info=230V] {};
\end{tikzpicture}
\end{document}
当我尝试编译它时,会出现以下错误:
包裹
pgfkeys
错误:我不知道密钥'/tikz/set ac current source graphic = ac current source IEC graphic'
,我将忽略它。也许你拼错了。
@morbusg 的解决方案与 Plain TeX 完美兼容,但我使用的是 LaTeX。也许我遗漏了什么?
答案1
我找到了一个完全符合我的要求的解决方案。
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\tikzset{circuit declare symbol = ac source}
\tikzset{set ac source graphic = ac source IEC graphic}
\tikzset{
ac source IEC graphic/.style=
{
transform shape,
circuit symbol lines,
circuit symbol size = width 3 height 3,
shape=generic circle IEC,
/pgf/generic circle IEC/before background=
{
\pgfpathmoveto{\pgfpoint{-0.8pt}{0pt}}
\pgfpathsine{\pgfpoint{0.4pt}{0.4pt}}
\pgfpathcosine{\pgfpoint{0.4pt}{-0.4pt}}
\pgfpathsine{\pgfpoint{0.4pt}{-0.4pt}}
\pgfpathcosine{\pgfpoint{0.4pt}{0.4pt}}
\pgfusepathqstroke
}
}
}
\begin{document}
\begin{tikzpicture}[circuit ee IEC]
\draw (0,0) to [ac source={info={110V 60Hz},near start},resistor={near end}] (3,0);
\draw (0,-1.5) to [ac source={volt=220,near start}, inductor={near end}] (3,-1.5);
\end{tikzpicture}
\end{document}
答案2
第一个是 Plain-TeX 版本,它有一些额外的定义,用于“包括”交流源图形作为可切换的(IEC/US/等)电路形状。这不是必需的;请参阅下面的精简版 LaTeX 版本。
\input tikz
\usetikzlibrary{circuits.ee.IEC}
\tikzset{circuit declare symbol = ac current source}
\tikzset{ac current source IEC graphic/.style={
circuit symbol lines,
circuit symbol size=width 2 height 2,
shape=generic circle IEC,
/pgf/generic circle IEC/before background={
\pgfpathmoveto{\pgfpoint{-0.8pt}{0pt}}
\pgfpathsine{\pgfpoint{0.4pt}{0.4pt}}
\pgfpathcosine{\pgfpoint{0.4pt}{-0.4pt}}
\pgfpathsine{\pgfpoint{0.4pt}{-0.4pt}}
\pgfpathcosine{\pgfpoint{0.4pt}{0.4pt}}
\pgfusepath{stroke}
},
transform shape
}
}
\tikzset{circuit ee IEC/.append style=
{set ac current source graphic = ac current source IEC graphic}
}
\tikzpicture[circuit ee IEC]
\draw node[ac current source, huge circuit symbols,info=230V] {};
\draw (1,0) node[ac current source, small circuit symbols,info=230V] {};
\endtikzpicture
\bye
编辑:LaTeX(没有额外的定义):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\tikzset{ac source/.style={
circuit symbol lines,
circuit symbol size = width 2 height 2,
shape = generic circle IEC,
/pgf/generic circle IEC/before background={
\pgfpathmoveto{\pgfpoint{-0.8pt}{0pt}}
\pgfpathsine{\pgfpoint{0.4pt}{0.4pt}}
\pgfpathcosine{\pgfpoint{0.4pt}{-0.4pt}}
\pgfpathsine{\pgfpoint{0.4pt}{-0.4pt}}
\pgfpathcosine{\pgfpoint{0.4pt}{0.4pt}}
\pgfusepath{stroke}
},
transform shape
}}
\begin{document}
\begin{tikzpicture}[circuit ee IEC,small circuit symbols]
\node[ac source,volt=230] {};
\end{tikzpicture}
\end{document}