为了完成我的论文,我需要在 LaTeX 文档中添加一些框图。有人建议我使用 TikZ。
这是我能找到的唯一示例代码。
你们有没有关于这个的一些教程/文档?
我尤其感兴趣的是如何将图形符号而不是文本放入框中。以及如何在块周围绘制虚线框。
就像是:
答案1
要将绘图放入块中,我建议您使用绘图创建一些宏,并将它们放入节点中,如下例所示
\documentclass[border=10]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand{\symbolA}{
\tikz \draw[red] (0,0)--(0,0.2)--(0.2,0.2)--(0.2,0.4)--(0.4,0.4);
}
\newcommand{\symbolB}{
\tikz[y={(0,-1)}] \draw[blue] (0,0)--(0,0.2)--(0.2,0.2)--(0.2,0.4)--(0.4,0.4);
}
\newcommand{\symbolC}{
\begin{tikzpicture}
\draw[fill=green] (0,0) circle (0.2cm);
\end{tikzpicture}
}
\begin{document}
\begin{tikzpicture}
\node[draw](A) at (0,0){\symbolA};
\node[draw, right=2em of A] (B) {\symbolB};
\node[draw, right=2em of B] (C) {\symbolC};
\draw[-latex] (A) -- (B);
\draw[-latex](B) -- (C);
\end{tikzpicture}
\end{document}
当然你可以用你引用的代码来使用它
\documentclass[border=10]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows}
\newcommand{\symbolA}{
\tikz \draw[red] (0,0)--(0,0.2)--(0.2,0.2)--(0.2,0.4)--(0.4,0.4);
}
\newcommand{\symbolB}{
\tikz[y={(0,-1)}] \draw[blue] (0,0)--(0,0.2)--(0.2,0.2)--(0.2,0.4)--(0.4,0.4);
}
\newcommand{\symbolC}{
\begin{tikzpicture}
\draw[fill=green] (0,0) circle (0.2cm);
\end{tikzpicture}
}
\begin{document}
\tikzstyle{block} = [draw, fill=blue!20, rectangle,
minimum height=3em, minimum width=6em]
\tikzstyle{sum} = [draw, fill=blue!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
% 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] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (controller) {\symbolA};
\node [block, right of=controller, pin={[pinstyle]above:Disturbances},
node distance=3cm] (system) {\symbolB};
% We draw an edge between the controller and system block to
% calculate the coordinate u. We need it to place the measurement block.
\draw [->] (controller) -- node[name=u] {$u$} (system);
\node [output, right of=system] (output) {};
\node [block, below of=u] (measurements) {\symbolC};
% Once the nodes are placed, connecting them is easy.
\draw [draw,->] (input) -- node {$r$} (sum);
\draw [->] (sum) -- node {$e$} (controller);
\draw [->] (system) -- node [name=y] {$y$}(output);
\draw [->] (y) |- (measurements);
\draw [->] (measurements) -| node[pos=0.99] {$-$}
node [near end] {$y_m$} (sum);
\end{tikzpicture}
\end{document}
但你也可以使用图表块包裹:http://www.texample.net/tikz/examples/schemabloc/。