[Tex/LaTex] Group multiple arrays

arraysformatting

I've got a State-Space system (4 matrices that go together), and rather than presenting each SS matrix on a new line I would like to group them together (and look nice while doing so).

I'm looking for the best way to do this.

The following code contains my 4 matrices (and works), but I encounter the following problems:

  1. When I put \begin{equation} \end{equation} around my code it gives errors

  2. All matrices have different sizes. Is there some way to make the formatting more pretty?

enter image description here

\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}

The above code is an array size 2×2 with arrays on all elements. I've considered using

\begin{equation}
\begin{split}
A & =matrix1 B=matrix2 \\
C & =matrix3 C=matrix4
\end{split}
\end{equation

But this wont even compile.

Best Answer

The hard part was using the same horizontal spacing in each array.

\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}

demo

Related Question