我有以下卡尔曼滤波器的框图:
我认为框的上边框和第一行数学之间的间距太大。我该如何减少间距以使其看起来更美观?
代码
\documentclass[varwidth=true, border=2pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\pgfplotsset{compat=1.13}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xcolor}
\begin{document}
\tikzstyle{block} = [draw, rectangle, minimum width=6em, align=center]
\newcommand*{\tran}{\top}
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
% Place the blocks
\node[text width=1cm, draw,
rounded corners=3pt,
label={[above,align=center]{Initial\\State}}] at (-1, 0) (initial)
{$$\mathbf{x}_0$$ $$P_0$$};
\node at (0.25, 0) (sum) {};
\node[block, text width=6cm,
label={[above,align=center]{Prediction}}] at (4, 0) (prediction)
{\begin{align*}
\mathbf{x}_{k+1}^{(P)} &= A x_k + B {\color{orange} a_k}\\
P_{k+1}^{(P)} &= A P_k A^\tran + C_k^{(r_s)}
\end{align*}};
\node [block, right of=prediction,
node distance=3cm, text width=1cm] at (6, -2) (iterUpdate)
{$$k \leftarrow k + 1$$};
\node [block, text width=6cm,
label={[above,align=center]{Innovation}}] at (4, -4) (innovation)
{\begin{align*}
K_k &= P_k^{(P)} H^\tran {(H P_k^{(P)} H^\tran + C_k^{(M)})}^{-1}\\
{\color{blue} x_k} &= \mathbf{x}_k^{(P)} + K_k \left ({\color{orange} z_k} - H \mathbf{x}_k^{(P)} \right )\\
{\color{blue} P_k} &= (I - K_k H) P_k^{(P)}
\end{align*}};
% Connect the nodes
\draw [->] (initial) -- (prediction);
\draw [->] (prediction.east) -| (iterUpdate.north);
\draw [->] (iterUpdate) |- (innovation);
\draw [->] (innovation.west) -| (sum);
\end{tikzpicture}
\end{document}
答案1
您只需在代码中添加一行即可做到这一点\setlength{\abovedisplayskip}{0pt}
,该行控制处于显示模式(非文本模式)的方程式上方的空间
输出
代码
\documentclass[varwidth=true, border=2pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\pgfplotsset{compat=1.13}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xcolor}
\begin{document}
\tikzstyle{block} = [draw, rectangle, minimum width=6em, align=center]
\newcommand*{\tran}{\top}
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
\setlength{\abovedisplayskip}{0pt}
% Place the blocks
\node[text width=1cm, draw,
rounded corners=3pt,
label={[above,align=center]{Initial\\State}}] at (-1, 0) (initial)
{$$\mathbf{x}_0$$ $$P_0$$};
\node at (0.25, 0) (sum) {};
\node[block, text width=6cm,
label={[above,align=center]{Prediction}}] at (4, 0) (prediction)
{\begin{align*}
\mathbf{x}_{k+1}^{(P)} &= A x_k + B {\color{orange} a_k}\\
P_{k+1}^{(P)} &= A P_k A^\tran + C_k^{(r_s)}
\end{align*}};
\node [block, right of=prediction,
node distance=3cm, text width=1cm] at (6, -2) (iterUpdate)
{$$k \leftarrow k + 1$$};
\node [block, text width=6cm,
label={[above,align=center]{Innovation}}] at (4, -4) (innovation)
{\begin{align*}
K_k &= P_k^{(P)} H^\tran {(H P_k^{(P)} H^\tran + C_k^{(M)})}^{-1}\\
{\color{blue} x_k} &= \mathbf{x}_k^{(P)} + K_k \left ({\color{orange} z_k} - H \mathbf{x}_k^{(P)} \right )\\
{\color{blue} P_k} &= (I - K_k H) P_k^{(P)}
\end{align*}};
% Connect the nodes
\draw [->] (initial) -- (prediction);
\draw [->] (prediction.east) -| (iterUpdate.north);
\draw [->] (iterUpdate) |- (innovation);
\draw [->] (innovation.west) -| (sum);
\end{tikzpicture}
\end{document}