# Latex, how to align matrices

I am working on an assignment. I have a matrix that I am trying to align, this is what it looks like.

I have two questions

1. How do I align these horizontally i.e how do I make columns 4,5 and 6 the same width as columns 1,2 and 3?
2. How to align these vertically i.e how do I make the lengths equal so that the top and bottom of all matrices align.

I am using the environment bsmallmatrix as I hope to apply this solution to a 24x24 matrix.

I have tried to use align* method described here and the arraystetch command described here, these did not get the desired results but it's possible I used them wrong.

Here is a sample of my Latex code.

\documentclass[a4 paper,11 pt]{article}
\usepackage{amsmath}
\usepackage{esvect}

\newenvironment{bsmallmatrix}
{\left[\begin{smallmatrix}}
{\end{smallmatrix}\right]}

\begin{document}

$$\frac{d^2}{dt^2} \begin{bsmallmatrix} X_e \\ Y_e \\ Z_e \\ X'_e \\ Y'_e \\ Z'_e \end{bsmallmatrix} = \begin{bsmallmatrix} 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \\ \ddot{\vv{r}}_{e_{x}} & 0 & 0 & 0 & 0 & 0 \\ 0 & \ddot{\vv{r}}_{e_{y}} & 0 & 0 & 0 & 0 \\ 0 & 0 & \ddot{\vv{r}}_{e_{z}} & 0 & 0 & 0\\ \end{bsmallmatrix} \begin{bsmallmatrix} X_e \\ Y_e \\ Z_e \\ X'_e \\ Y'_e \\ Z'_e \end{bsmallmatrix}$$

\end{document}


• you are forcing mis-alignment by using matrix for some and smallmatrix for others May 8 at 19:03
• pleased always post code in a form people can run to see the issue, deleting \begin{document} and \documentclass makes it harder for peopel to use the code. May 8 at 19:05
• @DavidCarlisle thank you for the tips, I've edited the posts to include these changes. This has fixed issue 2, by any chance would you have a solution for question 1?
– C Mc
May 8 at 19:29
• matrix doesn't have a standard way to control the width you can use array then the array package will let you use wc{15pt} or whatever width you want May 8 at 19:38

I propose using \bracketMatrixstack from the tabstackengine package. The row baselineskip and column gap are settable, and one can also ask that all columns be the same width (based on widest column content). The cell style may also be specified, here to \scriptstyle.

\documentclass[a4 paper,11 pt]{article}
\usepackage{amsmath}
\usepackage{esvect}
\usepackage{tabstackengine}
\TABstackMath
\TABstackMathstyle{\scriptstyle}% CELL STYLE
\setstackgap{L}{9pt}% ROW BASELINESKIP
\setstacktabbedgap{1pt}% INTER-COLUMN GAP
\fixTABwidth{T}% MAKE ALL COLUMNS EQUAL WIDTH
\begin{document}
$$\frac{d^2}{dt^2} \bracketMatrixstack{ X_e \\ Y_e \\ Z_e \\ X'_e \\ Y'_e \\ Z'_e } = \bracketMatrixstack{ 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \\ \ddot{\vv{r}}_{e_{x}} & 0 & 0 & 0 & 0 & 0 \\ 0 & \ddot{\vv{r}}_{e_{y}} & 0 & 0 & 0 & 0 \\ 0 & 0 & \ddot{\vv{r}}_{e_{z}} & 0 & 0 & 0 } \bracketMatrixstack{ X_e \\ Y_e \\ Z_e \\ X'_e \\ Y'_e \\ Z'_e }$$
\end{document}