# How to align multiline equations

I am trying to achieve a neat multi line equation. The equation is too big so I had to cut it half way (the first part of the equation). So this is what I ended up doing, the equation break after the equal sign. After this part, I am simplifying the equation. I would like the equal signs to line up with the first equal sign. But after I tried different solutions, I couldn't work it out.

Currently this is the latex code I am using:

\label{eqn:Acc_rot_matrix_3} \resizebox{0.9\columnwidth}{!}{  \begin{aligned} &\begin{bmatrix} a_x \\ a_y \\ a_z \end{bmatrix} =\\ &\begin{bmatrix} C_{\theta}C_{0} & C_{\theta}S_{0} & -S_{\theta} \\ S_{\phi}S_{\theta}C_{0} - C_{\phi}S_{0} & S_{\phi}S_{\theta}S_{0} + C_{\phi}C_{0} & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}C_{0} + S_{\phi}S_{0}\ & C_{\phi}S_{\theta}S_{0} - S_{\phi}C_{0} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ \\ &= \begin{bmatrix} C_{\theta}*1 & C_{\theta}*0 & - S_{\theta} \\ S_{\phi}S_{\theta}*1 - C_{\phi}*0 & S_{\phi}S_{\theta}*0 + C_{\phi}*1 & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}*1 + S_{\phi}*0 & C_{\phi}S_{\theta}*0 - S_{\phi}*1 & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ \\ &= \begin{bmatrix} C_{\theta} & 0 & -S_{\theta} \\ S_{\theta}S_{\phi} & C_{\phi} & S_{\phi}C_{\theta}\\ S_{\theta}C_{\phi} & -S_{\phi} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \end{aligned} }


I have tried using alignat for multiple alignments, but this didn't work. As well as alignedat. Code that I used for this was as following:

\label{eqn:Acc_rot_matrix_3} \resizebox{0.9\columnwidth}{!}{  \begin{alignedat}{2} &\begin{bmatrix} a_x \\ a_y \\ a_z \end{bmatrix} &=\\ &\begin{bmatrix} C_{\theta}C_{0} & C_{\theta}S_{0} & -S_{\theta} \\ S_{\phi}S_{\theta}C_{0} - C_{\phi}S_{0} & S_{\phi}S_{\theta}S_{0} + C_{\phi}C_{0} & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}C_{0} + S_{\phi}S_{0}\ & C_{\phi}S_{\theta}S_{0} - S_{\phi}C_{0} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ \\ & &= \begin{bmatrix} C_{\theta}*1 & C_{\theta}*0 & - S_{\theta} \\ S_{\phi}S_{\theta}*1 - C_{\phi}*0 & S_{\phi}S_{\theta}*0 + C_{\phi}*1 & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}*1 + S_{\phi}*0 & C_{\phi}S_{\theta}*0 - S_{\phi}*1 & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ \\ & &= \begin{bmatrix} C_{\theta} & 0 & -S_{\theta} \\ S_{\theta}S_{\phi} & C_{\phi} & S_{\phi}C_{\theta}\\ S_{\theta}C_{\phi} & -S_{\phi} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \end{alignedat} }


This is another example I tried:

\label{eqn:Acc_rot_matrix_3} \resizebox{0.9\columnwidth}{!}{  \begin{aligned} &\begin{bmatrix} a_x \\ a_y \\ a_z \end{bmatrix} &&=\\ &\begin{bmatrix} C_{\theta}C_{0} & C_{\theta}S_{0} & -S_{\theta} \\ S_{\phi}S_{\theta}C_{0} - C_{\phi}S_{0} & S_{\phi}S_{\theta}S_{0} + C_{\phi}C_{0} & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}C_{0} + S_{\phi}S_{0}\ & C_{\phi}S_{\theta}S_{0} - S_{\phi}C_{0} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ \\ &&= \begin{bmatrix} C_{\theta}*1 & C_{\theta}*0 & - S_{\theta} \\ S_{\phi}S_{\theta}*1 - C_{\phi}*0 & S_{\phi}S_{\theta}*0 + C_{\phi}*1 & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}*1 + S_{\phi}*0 & C_{\phi}S_{\theta}*0 - S_{\phi}*1 & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ \\ &&= \begin{bmatrix} C_{\theta} & 0 & -S_{\theta} \\ S_{\theta}S_{\phi} & C_{\phi} & S_{\phi}C_{\theta}\\ S_{\theta}C_{\phi} & -S_{\phi} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \end{aligned} }


With the result as following:

How can I align the first part of the equation as given in picture 1. And align the simplification equations with the equal sign of the first part of the equation?

• Welcome to TeX SX! Are you in single-column or two column mode? Commented Apr 17, 2022 at 15:33
• I am in two column mode, thank you for the reply Commented Apr 17, 2022 at 15:58
• Suggestion: Skip the second and third row. After all, there are only rather trivial simplifications done there. If they are needed, give them in the text. Commented Apr 17, 2022 at 19:29
• @mickep From school it is necessary to show these steps in equation form. So that's why they had to be added. Otherwise I would skip them as well. Commented Apr 17, 2022 at 20:41

Personally, I think it looks better when simplified like this.

Edit: version with the first equation broken:

\documentclass{article}
\usepackage{mathtools}
\begin{document}

\begin{aligned} &\mathop{\phantom{=}}{}\begin{bmatrix} a_x \\ a_y \\ a_z \end{bmatrix}\\ &= \begin{bmatrix} C_{\theta}C_{0} & C_{\theta}S_{0} & -S_{\theta} \\ S_{\phi}S_{\theta}C_{0} - C_{\phi}S_{0} & S_{\phi}S_{\theta}S_{0} + C_{\phi}C_{0} & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}C_{0} + S_{\phi}S_{0}\ & C_{\phi}S_{\theta}S_{0} - S_{\phi}C_{0} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ &= \begin{bmatrix} C_{\theta}*1 & C_{\theta}*0 & - S_{\theta} \\ S_{\phi}S_{\theta}*1 - C_{\phi}*0 & S_{\phi}S_{\theta}*0 + C_{\phi}*1 & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}*1 + S_{\phi}*0 & C_{\phi}S_{\theta}*0 - S_{\phi}*1 & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ \\ &= \begin{bmatrix} C_{\theta} & 0 & -S_{\theta} \\ S_{\theta}S_{\phi} & C_{\phi} & S_{\phi}C_{\theta}\\ S_{\theta}C_{\phi} & -S_{\phi} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \end{aligned}
\end{document}


• I do agree, but it won't fit in a two column article. And if I make it smaller so it would fit it won't be readable. So that's why I have to break the first equation Commented Apr 17, 2022 at 15:59
• @XandervandenBerg See my modified answer, then. Commented Apr 17, 2022 at 16:27
• Even with the modifications applied, the equation exceeds \columnwidth (if the article document class is loaded with the twocolumn option).
– Mico
Commented Apr 17, 2022 at 19:23
• Indeed that's why I used resizebox, the combination of breaking the equation and resizebox makes it fit. Commented Apr 17, 2022 at 19:34
• @FranckPastor Is it possible to put the first equal sign after the first part of the equation instead of after the equation break? I've had this result as well before. But couldn't figure out how to get the equal sign before the line break Commented Apr 17, 2022 at 20:39

You can play with the value of \BA@colsep:

    \documentclass[twocolumn]{article}
\usepackage{blkarray}
\usepackage{lipsum}
\makeatletter
\AtBeginDocument{\BA@colsep=1.5pt}
\makeatother

\begin{document}

$\begin{blockarray}{*{16}{c}} & c_1 & c_2 & c_3 & c_4 & c_5 & c_6 & c_7 & c_8 & c_9 & c_{10} & c_{11} & c_{12} & c_{13} & c_{14} & c_{15} \\ \begin{block}{c ccccccccccccccc } r_1 & | & & & & & & & & & & & & | & & \\ r_2 & & | & & & & & & & & & & & | & & \\ r_3 & & & | & & & & & & & & & & | & & \\ r_4 & & & & | & & & & & & & & & | & & \\ r_5 & & & & & | & & & & & & & & & | & \\ r_6 & & & & & & | & & & & & & & & | & \\ r_7 & & & & & & & | & & & & & & & | & \\ r_8 & & & & & & & & | & & & & & & | & \\ r_9 & & & & & & & & & | & & & & & & | \\ r_{10} & & & & & & & & & & | & & & & & | \\ r_{11} & & & & & & & & & & & | & & & & | \\ r_{12} & & & & & & & & & & & & | & & & | \\ \end{blockarray}$

\lipsum

\end{document}


You can use multline as there is no alignment, and smallmatrix as it's smaller

\documentclass[twocolumn]{article}

\usepackage{mathtools}

\begin{document}

\noexpand X\dotfill X
\setlength\arraycolsep{3pt}
\begin{multline}
\label{eqn:Acc_rot_matrix_3}
% No, only as a last resort, and not then \resizebox{0.9\columnwidth}{!}{ $\begin{bsmallmatrix} a_x \\ a_y \\ a_z \end{bsmallmatrix} \\ {}=\begin{bsmallmatrix} C_{\theta}C_{0} & C_{\theta}S_{0} & -S_{\theta} \\ S_{\phi}S_{\theta}C_{0} - C_{\phi}S_{0} & S_{\phi}S_{\theta}S_{0} + C_{\phi}C_{0} & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}C_{0} + S_{\phi}S_{0}\ & C_{\phi}S_{\theta}S_{0} - S_{\phi}C_{0} & C_{\phi}C_{\theta} \end{bsmallmatrix}\! \begin{bsmallmatrix} 0 \\ 0 \\ -g \end{bsmallmatrix} \\ {}=\begin{bsmallmatrix} C_{\theta}*1 & C_{\theta}*0 & - S_{\theta} \\ S_{\phi}S_{\theta}*1 - C_{\phi}*0 & S_{\phi}S_{\theta}*0 + C_{\phi}*1 & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}*1 + S_{\phi}*0 & C_{\phi}S_{\theta}*0 - S_{\phi}*1 & C_{\phi}C_{\theta} \end{bsmallmatrix}\! \begin{bsmallmatrix} 0 \\ 0 \\ -g \end{bsmallmatrix} \\ {}= \begin{bsmallmatrix} C_{\theta} & 0 & -S_{\theta} \\ S_{\theta}S_{\phi} & C_{\phi} & S_{\phi}C_{\theta}\\ S_{\theta}C_{\phi} & -S_{\phi} & C_{\phi}C_{\theta} \end{bsmallmatrix} \begin{bsmallmatrix} 0 \\ 0 \\ -g \end{bsmallmatrix} \end{multline} \noexpand X\dotfill X \end{document}  • Is it possible to put the first equal sign after the first part of the equation instead of after the equation break? I've had this result as well before. But couldn't figure out how to get the equal sign before the line breal Commented Apr 17, 2022 at 16:27 • @XandervandenBerg sure, just use ={}\\  instead of \\{}= Commented Apr 17, 2022 at 16:28 • Two questions, could you explain why {} are used? And the comment in the code. It states resizebox as last resort, could you explain this as well why? Commented Apr 17, 2022 at 16:49 • @XandervandenBerg compare $=2$ and ${}=2\$ it ensures relation spacing. using \resizebox on text, math, tables, etc means every display uses a different, arbitrary, font size and makes ypographers weep. If you need a smaller size, use \small or some oher pre-determined size. Commented Apr 17, 2022 at 17:28

Here's a solution that employs a nested equation/multlined combination, reduces the font size linearly by 10%, and temporarily sets the low-level math spacing parameters \thinmuskip, \medmuskip, and \thickmuskip to (close to) zero.

\documentclass[twocolumn]{article}
\usepackage{mathtools}

\begin{document}
\hrule % draw line across width of column

\begingroup
\small
\thinmuskip=0mu    % default value: 3mu
\medmuskip=0mu     % default value: 4mu plus/minus "glue"
\thickmuskip=0.5mu % default value: 5mu plus/minus "glue"
\arraycolsep=2.5pt % default value: 5pt

$$\label{eqn:Acc_rot_matrix_3} \begin{multlined}[b] \begin{bmatrix} a_x \\ a_y \\ a_z \end{bmatrix} \\ = \begin{bmatrix} C_{\theta}C_{0} & C_{\theta}S_{0} & -S_{\theta} \\ S_{\phi}S_{\theta}C_{0} - C_{\phi}S_{0} & S_{\phi}S_{\theta}S_{0} + C_{\phi}C_{0} & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}C_{0} + S_{\phi}S_{0}\ & C_{\phi}S_{\theta}S_{0} - S_{\phi}C_{0} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ = \begin{bmatrix} C_{\theta}*1 & C_{\theta}*0 & - S_{\theta} \\ S_{\phi}S_{\theta}*1 - C_{\phi}*0 & S_{\phi}S_{\theta}*0 + C_{\phi}*1 & S_{\phi}C_{\theta}\\ C_{\phi}S_{\theta}*1 + S_{\phi}*0 & C_{\phi}S_{\theta}*0 - S_{\phi}*1 & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \\ = \begin{bmatrix} C_{\theta} & 0 & -S_{\theta} \\ S_{\theta}S_{\phi} & C_{\phi} & S_{\phi}C_{\theta}\\ S_{\theta}C_{\phi} & -S_{\phi} & C_{\phi}C_{\theta} \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ -g \end{bmatrix} \end{multlined}$$
\endgroup
\hrule
\end{document}
`