我有一个状态空间系统(4 个组合在一起的矩阵),而不是在新行上显示每个 SS 矩阵,我希望将它们组合在一起(并且这样做时看起来很漂亮)。
我正在寻找实现此目的的最佳方法。
以下代码包含我的 4 个矩阵(并且有效),但我遇到以下问题:
当我输入
\begin{equation} \end{equation}
我的代码时它会出现错误所有矩阵的大小都不同。有没有什么方法可以让格式更美观?
\documentclass[11pt,a4paper]{article}
\begin{document}
$\begin{array}{ll}
A = \left[\begin{array}{cccc}
0&0&1&0\\
0&0&0&1\\
\frac{-k}{J_1}&\frac{k}{J_1}&\frac{-d}{J_1}&\frac{d}{J_1}\\
\frac{k}{J_2}&\frac{-k}{J_2}&\frac{d}{J_2}&\frac{-d}{J_2}
\end{array}\right] & B = \left[\begin{array}{c}
0\\0\\\frac{1}{J_1}\\0
\end{array}\right] \\
C = \left[\begin{array}{cccc}0&0&1&0\end{array}\right]& D = \left[\begin{array}{c}0\end{array}\right]\\
\end{array}$
\end{document}
上面的代码是一个大小为 2x2 的数组,所有元素都是数组。我考虑过使用
\begin{equation}
\begin{split}
A & =matrix1 B=matrix2 \\
C & =matrix3 C=matrix4
\end{split}
\end{equation
但这甚至无法编译。
答案1
困难的部分是在每个阵列中使用相同的水平间距。
\documentclass[11pt,a4paper]{article}
\usepackage{mathtools}
\newcommand{\cell}[1]{\makebox[15pt]{#1}}% adjust column widths
\begin{document}
\def\arraystretch{1.4}% adjust row spacing
\begin{align*}
A &= \begin{bmatrix}
\cell{0}&\cell{0}&\cell{1}&\cell{0}\\ % set spacing for one row
0&0&0&1\\
\frac{-k}{J_1}&\frac{k}{J_1}&\frac{-d}{J_1}&\frac{d}{J_1}\\
\frac{k}{J_2}&\frac{-k}{J_2}&\frac{d}{J_2}&\frac{-d}{J_2}
\end{bmatrix} & B &= \begin{bmatrix}
\cell{0}\\0\\\frac{1}{J_1}\\0
\end{bmatrix} \\
C &= \:\begin{bmatrix} \cell{0}&\cell{0}&\cell{1}&\cell{0} \end{bmatrix} & D &= \:\begin{bmatrix} \cell{0} \end{bmatrix}\\
\end{align*}
\end{document}
答案2
像这样?
嗯,上面的图片是由以下人员绘制的:
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning}
\begin{document}
\begin{tikzpicture}[node distance=3mm,
every node/.style = {inner xsep=0pt,
minimum width=2em, minimum height=3ex},
every left delimiter/.style={xshift=1em},
every right delimiter/.style={xshift=-1em}
]
\matrix (m11) [matrix of math nodes,%
{left delimiter=[},{right delimiter=]}]
{
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\frac{-k}{J_1}
& \frac{k}{J_1}
& \frac{-d}{J_1}
& \frac{d}{J_1} \\
\frac{k}{J_2}
& \frac{-k}{J_2}
& \frac{d}{J_2}
& \frac{-d}{J_2} \\
};
\node (n11) [left=of m11] {$A =$};
\node (n12) [right=7mm of m11] {$B =$};
\matrix (m12) [matrix of math nodes,%
{left delimiter=[},{right delimiter=]},%
right=of n12]
{
0 \\ 0 \\ \frac{k}{J_1} \\ 0 \\
};
% second row
\matrix (m21) [matrix of math nodes, inner ysep=1mm,%
{left delimiter=[},{right delimiter=]},%
below=of m11]
{
0 & 0 & 1 & 0 \\
};
\node (n21) [left=of m21] {$C =$};
\node (n22) [right=7mm of m21] {$D =$};
\matrix (m22) [matrix of math nodes, inner ysep=1mm,%
{left delimiter=[},{right delimiter=]},%
right=of n22]
{
0 \\
};
\end{tikzpicture}
\end{document}
附註:
上图您可以将其包含在数学环境中。为了更好地定位方程编号,您需要添加baseline=(current bounding box.center)
选项tikzpicture
:
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning}
\begin{document}
\begin{equation}
\begin{tikzpicture}[baseline=(current bounding box.center),
%... the same as in MWE above ...
\end{tikzpicture}
\end{equation}
\end{document}