# Group multiple arrays

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? \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 2x2 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.

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

\documentclass[11pt,a4paper]{article}
\usepackage{mathtools}

\begin{document}
\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} • Thanks your result looks very nice, however this will not compile. (placed in a new texfile to be sure and it gives over 20 errors). Sep 8, 2016 at 9:38
• Got it to compile (the empty line after \begin{align} should be removed. Sep 8, 2016 at 9:52
• using it within \begin{equation} \end{equation} and using aligned instead of align* gave the desired final result. Thanks! Sep 8, 2016 at 11:03

Like this? well, above image is drawn by:

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


Addedndum: above picture you can enclose in math environment. for better positioning of equation number you need to add baseline=(current bounding box.center) option to 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} • Looks very nice and it compiles without problems! Would there be someway to put it in an \begin{equation} \end{equation} environment? Sep 8, 2016 at 9:40
• @Niwol, of course, it is possible, See addendum in my answer. Sep 8, 2016 at 10:06