我正在尝试绘制一幅代表控制理论图的图。
我基本上已经做到了,但是有两个问题:
我需要在大框中第一个方程的 x(t) 上方加一个点。当我将其置于数学模式时,它会绘制四条线而不是两条,或者,根据我如何拆分数学模式,它会将所有点都放在一条线上。有没有办法在不改变框布局的情况下将那个该死的点放在 x 上方?
带有 y(.) 的 RHS 箭头太长了。我想将其缩短到接近带有 v(.) 的 LHS 箭头的长度,这样看起来会更美观!
这是我的代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning, quotes}
\begin{document}
\tikzstyle{block} = [draw, fill=white, rectangle,
minimum height=6em, minimum width=12em]
\tikzstyle{sum} = [draw, fill=white, circle, node distance=2cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{center}
\begin{tikzpicture}[auto, node distance=4cm,>=latex']
\node [input, name=input] {};
\node [sum, right of=input] (sum) {B};
\node [block, right of=sum] (controller) {\begin{array} \dot{x}(t)=&Ax(t)+Bu(t)\\ x(0)=&x_0 \end{array}};
!\node [sum, right of=controller, node distance=3.651cm] (mat) {C};
\node [sum, below of=controller] (K) {K};
\node [output, right of=controller] (output) {C};
\node [input, name=end, right of=output, node distance=5cm] {};
\coordinate [below of=sum] (measurements) {};
\coordinate [right of=output](fin) {};
\coordinate[left of =output, xshift=2.7cm] (nodek) {};
\draw [draw,->] (input) -- node {$v(\bullet)$} (sum);
\draw [->] (sum) -- node {$u(\bullet)$} (controller);
\draw [->] (controller) -- node[name=(x)] {$x(\bullet)$} (mat) {};
\draw [->] (output) -- node {$y(\bullet)$} (fin);
\draw [-] (nodek) |- (K);
\draw [->] (K) -| (sum);
\end{tikzpicture}
\end{center}
\end{document}
答案1
如同jak123 的回答很好但略有不同:
\mywidth
我利用的是密钥,而不是引入新的长度node distance=2cm
。- 我也切换到
\tikzset
语法而不是\tikzstyle
。 - 我删除了代码中多余的元素。
这是您的代码中出现的问题
- 您忘记在数组中添加列说明符,这就是它不起作用的原因。
- 您正在加载但未使用定位库。
- 几个坐标是多余的。
结果如下:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\begin{document}
\tikzset{block/.style={draw, fill=white, rectangle,
minimum height=6em, minimum width=12em},
sum/.style={draw, fill=white, circle, node distance=2cm},
input/.style={coordinate},
output/.style={coordinate}}
\begin{center}
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
\node [input, name=input] {};
\node [sum, right= of input] (sum) {B};
\node [block, right=of sum,align=left] (controller)
{$\begin{array}{r@{\,}l} \dot{x}(t)=&Ax(t)+Bu(t)\\ x(0)=&x_0 \end{array}$};
\node [sum, right=of controller] (mat) {C};
\node [sum, below=1cm of controller] (K) {K};
\coordinate [below=of sum] (measurements) {};
\coordinate [right=1.5cm of mat](fin) {};
\draw [draw,->] (input) -- node {$v(\bullet)$} (sum);
\draw [->] (sum) -- node {$u(\bullet)$} (controller);
\draw [->] (controller) -- node[name=x,above,midway] {$x(\bullet)$}
coordinate[midway] (x) (mat);
\draw [->] (mat) -- node[midway,above] {$y(\bullet)$} (fin);
\draw [-] (x) |- (K);
\draw [->] (K) -| (sum);
\end{tikzpicture}
\end{center}
答案2
像这样?
\documentclass{minimal}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning, quotes}
\newlength{\mywidth}
\setlength{\mywidth}{2cm}
\begin{document}
\tikzstyle{block} = [draw, fill=white, rectangle,
minimum height=6em, minimum width=12em]
\tikzstyle{sum} = [draw, fill=white, circle, node distance=2cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{center}
\begin{tikzpicture}[auto, node distance=4cm,>=latex']
\node [input, name=input] {};
\node [sum, right=\mywidth of input] (sum) {B};
\node [block, right=\mywidth of sum] (controller) {$\begin{array}{ccc} \dot{x}(t)&=&Ax(t)+Bu(t)\\ x(0)&=&x_0 \end{array}$};
\node [sum, right=\mywidth of controller] (mat) {C};
\node [sum, below=1cm of controller] (K) {K};
\node [output, right=\mywidth of controller] (output) {C};
\node [input, name=end, right=\mywidth of output] {};
\coordinate [below=\mywidth of sum] (measurements) {};
\coordinate [right=\mywidth of output] (fin) {};
\coordinate[left = \mywidth/2 of output] (nodek) {};
\draw [draw,->] (input) -- node {$v(\bullet)$} (sum);
\draw [->] (sum) -- node {$u(\bullet)$} (controller);
\draw [->] (controller) -- node[name=(x)] {$x(\bullet)$} (mat) {};
\draw [->] (mat) -- node {$y(\bullet)$} (fin);
\draw [-] (nodek) |- (K);
\draw [->] (K) -| (sum);
\end{tikzpicture}
\end{center}
\end{document}