3

This code

\begin{bmatrix} 
        a_{11} & a_{12} & a_{13} & a_{14} \\
        a_{21} & a_{22} & a_{23} & a_{24} \\
        a_{31} & a_{32} & a_{33} & a_{34} 
    \end{bmatrix}
    \begin{bmatrix}
        5 & 6 & 7 & 8 \\
        4 & 3 & 2 & 1 \\
        6 & 7 & 8 & 9
\end{bmatrix}

generates two matrices side by side. How can I make them on top of each other?

  • 1
    Is mere stacking required, or do columns need to align? If the former, \documentclass{article} \usepackage{amsmath,stackengine} \stackMath \begin{document} \[ \stackon{ \begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \end{bmatrix} }{ \begin{bmatrix} 5 & 6 & 7 & 8 \\ 4 & 3 & 2 & 1 \\ 6 & 7 & 8 & 9 \end{bmatrix} } \] \end{document} – Steven B. Segletes Aug 23 '21 at 18:12
  • Or this: \documentclass{article} \usepackage{amsmath} \begin{document} \[ \begin{matrix} {\begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \end{bmatrix}}\\ {\begin{bmatrix} 5 & 6 & 7 & 8 \\ 4 & 3 & 2 & 1 \\ 6 & 7 & 8 & 9 \end{bmatrix}} \end{matrix} \] \end{document} ...but only if columns need not align – Steven B. Segletes Aug 23 '21 at 18:17

3 Answers3

7

I suggest you place both bmatrix environments inside a gather* environment.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for 'bmatrix' and 'gather*' environments

\begin{document} \begin{gather} \begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \ a_{21} & a_{22} & a_{23} & a_{24} \ a_{31} & a_{32} & a_{33} & a_{34} \end{bmatrix} \ % <-- force a line break \begin{bmatrix} 5 & 6 & 7 & 8 \ 4 & 3 & 2 & 1 \ 6 & 7 & 8 & 9
\end{bmatrix} \end{gather
} \end{document}

Mico
  • 506,678
5

Here are some options; in principle, wrap the two matrices inside an array and separate them using a regular line break \\:

enter image description here

\documentclass{article}

\usepackage{amsmath,eqparbox}

% https://tex.stackexchange.com/a/34412/5764 \makeatletter \NewDocumentCommand{\eqmathbox}{o O{c} m}{% \IfValueTF{#1} {\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}} {\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}} \mathpalette\eqmathbox@{#3} } \makeatother

\begin{document}

[ \begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \ a_{21} & a_{22} & a_{23} & a_{24} \ a_{31} & a_{32} & a_{33} & a_{34} \end{bmatrix} \begin{bmatrix} 5 & 6 & 7 & 8 \ 4 & 3 & 2 & 1 \ 6 & 7 & 8 & 9 \end{bmatrix} ]

[ \begin{array}{@{} c @{}} \begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \ a_{21} & a_{22} & a_{23} & a_{24} \ a_{31} & a_{32} & a_{33} & a_{34} \end{bmatrix} \ \begin{bmatrix} 5 & 6 & 7 & 8 \ 4 & 3 & 2 & 1 \ 6 & 7 & 8 & 9 \end{bmatrix} \end{array} \qquad \begin{array}{@{} c @{}} \begin{bmatrix} \eqmathbox[aa]{a_{11}} & \eqmathbox[aa]{a_{12}} & \eqmathbox[aa]{a_{13}} & \eqmathbox[aa]{a_{14}} \ a_{21} & a_{22} & a_{23} & a_{24} \ a_{31} & a_{32} & a_{33} & a_{34} \end{bmatrix} \ \[\dimexpr-\normalbaselineskip+\jot] \begin{bmatrix} \eqmathbox[aa]{5} & \eqmathbox[aa]{6} & \eqmathbox[aa]{7} & \eqmathbox[aa]{8} \ 4 & 3 & 2 & 1 \ 6 & 7 & 8 & 9 \end{bmatrix} \end{array} ]

\end{document}

The addition of eqparbox (and \eqmathbox) depends on whether you want the entries to be aligned across the bmatrix-es. You can also consider blkarray.

Werner
  • 603,163
2

Maybe the OP wants the columns of the first matrix aligned with the columns of the second. It's possible with {NiceMatrix} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

[\begin{NiceMatrix} a_{11} & a_{12} & a_{13} & a_{14} \ a_{21} & a_{22} & a_{23} & a_{24} \ a_{31} & a_{32} & a_{33} & a_{34} \[1mm] 5 & 6 & 7 & 8 \ 4 & 3 & 2 & 1 \ 6 & 7 & 8 & 9
\CodeAfter \SubMatrix[{1-1}{3-4}] \SubMatrix[{4-1}{6-4}] \end{NiceMatrix}]

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250