创建和导入自定义 tikz 符号

创建和导入自定义 tikz 符号

我创建了一个自定义符号开关,我想使用节点命令将其包含在我的框图中,但失败了(编译错误)。这是我所做的:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes, arrows, fit}
\begin{document}

\newcommand\switch[0] {
    \begin{tikzpicture}
        \draw (0, 0) -- (1, 0) (1, 1) -- (2, 0) -- (3, 0);
        \draw [->, thick] (2, 1) .. controls +(left:5mm) and +(up:5mm) .. (1, 0);
    \end{tikzpicture}
}

My symbol is \switch
\end{document}

欢迎提出任何想法。提前致谢。

编辑

抱歉,我理解错了。我的意思是,当我在框图中导入此符号时,编译失败:未定义的控制序列。这是我的完整代码:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}

\newcommand\switch[0] {
    \begin{tikzpicture}
        \draw (0, 0) -- (1, 0) (1, 1) -- (2, 0) -- (3, 0);
        \draw [->, thick] (2, 1) .. controls +(left:5mm) and +(up:5mm) .. (1, 0);
    \end{tikzpicture}
}

\tikzstyle{block} = [draw, fill=gray!20, rectangle, 
    minimum height=2em, minimum width=4em]
\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\tikzstyle{integrator} = [draw, fill = gray!20, rectangle, minimum height = 2.5em, minimum width = 2em]
\tikzstyle{gain} = [draw, fill = gray!20, rectangle, minimum height = 2em, minimum width = 2em]

% The block diagram code is probably more verbose than necessary
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
    % We start by placing the blocks
    \node [input, name=input] {$\omega_R(z)$};
    \node [sum, right of=input] (sum) {};
    \node [\switch, right of=sum] (switch1){};
    \node [block, right of=sum] (Gc) {$G_c(z)$};
    \node [block, right of=Gc, node distance = 2.5cm] (B0) {$B_0(z)$};
    \node [block, right of = B0] (Gp) {$G_p(s)$};
    %\node [block, right of = Gp] (integrator) {$\frac{1}{s}$};
           % node distance=3cm] (B0) {System};
    % We draw an edge between the Gc and B0 block to 
    % calculate the coordinate Mz. We need it to place the measurement block. 
    \draw [->] (Gc) -- node[name=Mz] {$M(z)$} (B0);
    \node [block, right of = B0] (Gp) {$G_p(s)$};
    \node [integrator, right of = Gp] (integrator1) {$\frac{1}{s}$};
    \node [output, right of = integrator1] (output) {};
    \node [integrator, below of = Gp] (s) {$s$};
    \node [gain, below of = B0] (gain1) {$\frac{1}{K}$};

    % Once the nodes are placed, connecting them is easy. 
    \draw [draw,->] (input) -- node {$\omega_R(z)$} (sum);
    \draw [->] (sum) -- (switch1);
    \draw [->] (switch1) -- node {$e(z)$} (Gc);
    \draw [->] (B0) -- node {} (Gp);
    \draw [->] (Gp) -- node {$\omega(s)$} (integrator1);
    \draw [->] (integrator1) -- node [name=y] {$\theta (s)$}(output);
    \draw [->] (y) |- (s);
    \draw [->] (s) -- node {$rad/s$} (gain1);
    \draw [->] (gain1) -| node[pos=0.99] {$-$} 
        node [near end] {$\omega(z)$ (LSB)} (sum);
\end{tikzpicture}

\end{document}

相关内容