我是 LaTeX 的新手,正在尝试绘制类似图中的图表:
这个问题已得到解答,以下是类似图表的代码。
\documentclass{standalone}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20,text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,text width=5em, text centered, minimum height=4em]
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,minimum height=2em]
\tikzstyle{line} = [draw, -stealth, thick]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinfor future referenceate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\begin{tikzpicture}[auto,node distance =3cm,>=latex',
path/.style={->, >=stealth, postaction = decorate},
decoration={markings, mark = at position 1cm with {\arrow[black]{stealth}}
}]
% Place nodes
\node [input, name = input]{Input command};
\node [block, right of = input] (control) {Controller $C(\theta_c)$};
\node [block, right of = control](plant){Plant $G(\theta^*$)};
\node [right of = plant] (output){y};
\node [block, below of = plant][yshift=1.25cm] (O_p_e) {Online Parameter Estimator};
\node [block, below of = O_p_e] [yshift=1cm](C_c_p) {Calculation of control parameters};
\draw[draw,->] ([yshift=-1em]input) -- node [above of = input, node distance = 1em]{Input} ([yshift=-1em]control.west);
\draw [->] (control) -- node {$u$} (plant);
\draw [->] (O_p_e) -- node {$\theta(t)$}(C_c_p);
\draw [->] (control) -- (4.5,0) |- node {} (O_p_e);
\draw [->] (C_c_p) -| node {$\theta_c(t)$} (control);
\path[line] (plant) -- (output);
\draw [->] (plant) -- (7.5,0) |- node {} (O_p_e);
\draw [->] (plant) -- (7.5,0) -- (7.5,1) -| (0.5,1) |- node {} ([yshift = -0.2cm]control.north west);
\end{tikzpicture}
\end{document}
答案1
以下是使用tikz-dsp (Digital Signal Processing)
库;可以按照 TeXample.net 提供的链接下载该库。
我为加法器定义了两种新样式,以获取原始问题中图片所示的标签位置:
\documentclass{article}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{dsp,fit}
\makeatletter
\dspdeclareoperator{dspvoidshapeadder}{
% Coordinate offset for the plus
\pgfutil@tempdima=\radius
\pgfutil@tempdima=0.55\pgfutil@tempdima
\pgfusepathqstroke
}
\tikzset{
vdspadder/.style={
shape=dspvoidshapeadder,
line cap=rect,
line join=rect,
line width=\dspblocklinewidth,
minimum size=\dspoperatordiameter,
label={185:$+$},
label={265:$-$}
},
vadspadder/.style={
shape=dspvoidshapeadder,
line cap=rect,
line join=rect,
line width=\dspblocklinewidth,
minimum size=\dspoperatordiameter,
label=below right:$-$,
label=above right:$+$
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
% the nodes
\matrix[row sep=10mm, column sep=10mm]
{
& \node[vdspadder] (g1) {};
&
& \node[dspsquare] (g2) {$k_{\textrm{pr}}$};
& \node[dspfilter,text width=2cm] (g3) {Yaw Model}; \\
\node[dspnodeopen,label=above left:$r_{des}$] (g4) {};
& & &
& \node[dspfilter,text width=2cm,text height=1.5em,text depth=2em] (g5)
{Adaptation \\Law};
& \node[vadspadder] (g6) {}; \\
& \node[vdspadder] (g7) {};
& \node[dspsquare] (g8) {$k_{\textrm{pr}}$};
& \node[dspsquare] (g9) {$K$};
& \node[dspfilter,text width=2cm] (g10) {Yaw Plant}; \\
};
% the connections
\draw (g4) -- +(-20pt,0);
\draw[dspconn] (g4) -- (g5);
\draw[dspconn] (g4) |- coordinate[pos=0.85] (aux4) (g1);
\draw[dspconn] (g1) -- (g2);
\draw[dspconn] (g2) -- node[above] {$\delta_{\textrm{mod}}$} (g3);
\draw[dspconn] (g3) -| node[dspnodeopen,pos=0.25] (aux1) {} (g6) node[label=right:$r_{\textrm{mod}}$,pos=0.75] {};
\draw[dspconn] (g6) -- node[auto,swap] {$e$} (g5);
\draw[dspconn] (aux1) -- +(0,-30pt) -| (g1);
\draw[dspconn] (g4) |- (g7);
\draw[dspconn] (g7) -- (g8);
\draw[dspconn] (g8) -- (g9);
\draw[dspconn] (g9) -- node[below,pos=0.25] {$\delta$} (g10);
\draw[dspconn] (g10) -| node[dspnodeopen,pos=0.25] (aux2) {} (g6) node[label=right:$r$,pos=0.75] {};
\draw[dspconn] (aux2) |- (g5.-20);
\draw[dspconn] (aux2) |- +(0,-30pt) -| (g7);
\draw (g5.270) |- +(0,-22pt) -| (g9);
\draw[dspconn] (g9.south) -- +(0,-10pt);
% the fitting dashed nodes
\coordinate (aux3) at ([yshift=-20pt]aux1);
\node[draw,inner xsep=10pt,inner ysep=20pt,dashed,fit=(aux4) (aux3),label=above:{Closed-Loop Yaw Model}] {};
\node[draw,inner xsep=20pt,inner ysep=12pt,dashed,fit=(g8) (g9),label=above:{Yaw Rate Controller}] {};
\end{tikzpicture}
\end{document}