# Split long expression inside bmatrix environment

I am new to this and so please excuse my ignorance.

I have an equation Ax = b, where A is a 3 x 3 matrix. Because some of the elements in the matrix A contain long expressions, latex is not able to fit the equation neatly across the page (it causes the equation number to overspill, see image below). I wish to avoid splitting the matrix A over two rows. Instead, I would like to split the (long) elements over two lines if possible such that the equation fits on one row across the page. Any help would be greatly appreciated. My code is as follows:

\documentclass[11pt]{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm, bm}

\begin{document}

$$\begin{bmatrix} \mathbf{i}_{w}\\ \mathbf{j}_{w}\\ \mathbf{k}_{w} \end{bmatrix} = \begin{bmatrix} \cos\gamma \cos\chi & \cos\gamma \sin\chi & -\sin\chi \\ \sin\mu \sin\gamma \cos\chi - \cos\mu \sin\chi & \sin\mu \sin\gamma \sin\chi + \cos\mu \cos\chi & \sin\mu \cos\gamma \\ \cos\mu \sin\gamma \cos\chi + \sin\mu \sin\chi & \cos\mu\sin\gamma\sin\chi-\sin\mu\cos\chi & \cos\mu\cos\gamma \end{bmatrix} \begin{bmatrix} \mathbf{i}_{h}\\ \mathbf{j}_{h}\\ \mathbf{k}_{h} \end{bmatrix}$$

\end{document}


You can nest matrix, giving some more room between the main rows.

\documentclass[11pt]{book}
\usepackage{amsmath,amssymb,amsthm, bm}

\begin{document}

$$\begin{bmatrix} \mathbf{i}_{w}\\ \mathbf{j}_{w}\\ \mathbf{k}_{w} \end{bmatrix} = \begin{bmatrix} \cos\gamma \cos\chi & \cos\gamma \sin\chi & -\sin\chi \\[1ex] \begin{matrix} \sin\mu \sin\gamma \cos\chi \\ \hfill{}- \cos\mu \sin\chi \end{matrix} & \begin{matrix} \sin\mu \sin\gamma \sin\chi \\ \hfill{}+ \cos\mu \cos\chi \end{matrix} & \sin\mu \cos\gamma \\[2.5ex] \begin{matrix} \cos\mu \sin\gamma \cos\chi \\ \hfill{}+ \sin\mu \sin\chi \end{matrix} & \begin{matrix} \cos\mu\sin\gamma\sin\chi \\ \hfill{}- \sin\mu\cos\chi \end{matrix} & \cos\mu\cos\gamma \end{bmatrix} \begin{bmatrix} \mathbf{i}_{h}\\ \mathbf{j}_{h}\\ \mathbf{k}_{h} \end{bmatrix}$$

\end{document}


You can also align the columns, by replicating the contents with phantoms:

\documentclass[11pt]{book}
\usepackage{amsmath,amssymb,amsthm, bm}

\begin{document}

$$\begin{bmatrix} \mathbf{i}_{w}\\[1ex] \mathbf{j}_{w} \vphantom{\begin{matrix} \sin\mu \sin\gamma \cos\chi \\ \hfill{}- \cos\mu \sin\chi \end{matrix} } \\[2.5ex] \mathbf{k}_{w} \vphantom{\begin{matrix} \cos\mu \sin\gamma \cos\chi \\ \hfill{}+ \sin\mu \sin\chi \end{matrix} } \end{bmatrix} = \begin{bmatrix} \cos\gamma \cos\chi & \cos\gamma \sin\chi & -\sin\chi \\[1ex] \begin{matrix} \sin\mu \sin\gamma \cos\chi \\ \hfill{}- \cos\mu \sin\chi \end{matrix} & \begin{matrix} \sin\mu \sin\gamma \sin\chi \\ \hfill{}+ \cos\mu \cos\chi \end{matrix} & \sin\mu \cos\gamma \\[2.5ex] \begin{matrix} \cos\mu \sin\gamma \cos\chi \\ \hfill{}+ \sin\mu \sin\chi \end{matrix} & \begin{matrix} \cos\mu\sin\gamma\sin\chi \\ \hfill{}- \sin\mu\cos\chi \end{matrix} & \cos\mu\cos\gamma \end{bmatrix} \begin{bmatrix} \mathbf{i}_{h}\\[1ex] \mathbf{j}_{h} \vphantom{\begin{matrix} \sin\mu \sin\gamma \cos\chi \\ \hfill{}- \cos\mu \sin\chi \end{matrix} } \\[2.5ex] \mathbf{k}_{h} \vphantom{\begin{matrix} \cos\mu \sin\gamma \cos\chi \\ \hfill{}+ \sin\mu \sin\chi \end{matrix} } \end{bmatrix}$$

\end{document}


Now judge yourself about the aesthetics.

• Dear egreg, many thanks for sharing your solution. I had one additional question, is it possible to modify your solution above such that all of the rows in the equation are aligned horizontally too, i.e., can we achieve a situation where the elements of the vectors x and b are at the same height as their corresponding rows in matrix A? Thanking you in advance, Bob. Mar 9 '17 at 10:47
• @Bob1986 Sure, but you need “phantoms” and the input is quite complicated. Mar 9 '17 at 11:33
• Dear egreg, This is precisely what I was looking for (or 'bang-on' as one would say in Scotland!) Thanking you again! Regards Bob. Mar 9 '17 at 11:47

You can either use the aligned environment, or use the medsize environment from nccmath:

\documentclass[11pt]{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm, bm}
\usepackage[showframe]{geometry}
\usepackage{nccmath}

\begin{document}

\begin{bmatrix} \mathbf{i}_{w}\\ \mathbf{j}_{w}\\ \mathbf{k}_{w} \end{bmatrix} = \begin{bmatrix} \cos\gamma \cos\chi & \cos\gamma \sin\chi & -\sin\chi \\ \begin{aligned}[t]\sin\mu \sin\gamma \cos\chi & \\[-1.2ex]- \cos\mu \sin\chi &\end{aligned} & \begin{aligned}[t]\sin\mu \sin\gamma \sin\chi & \\[-1.2ex]+ \cos\mu \cos\chi & \end{aligned} & \sin\mu \cos\gamma \\ \begin{aligned}[t]\cos\mu \sin\gamma \cos\chi & \\[-1.2ex]+ \sin\mu \sin\chi & \end{aligned} & \begin{aligned}[t]\cos\mu\sin\gamma\sin\chi &\\[-1.2ex] -\sin\mu\cos\chi & \end{aligned} & \cos\mu\cos\gamma \end{bmatrix} \begin{bmatrix} \mathbf{i}_{h}\\ \mathbf{j}_{h}\\ \mathbf{k}_{h} \end{bmatrix}

$$\begin{medsize} \begin{bmatrix} \mathbf{i}_{w}\\ \mathbf{j}_{w}\\ \mathbf{k}_{w} \end{bmatrix} = \begin{bmatrix} \cos\gamma \cos\chi & \cos\gamma \sin\chi & -\sin\chi \\ \sin\mu \sin\gamma \cos\chi - \cos\mu \sin\chi & \sin\mu \sin\gamma \sin\chi + \cos\mu \cos\chi & \sin\mu \cos\gamma \\ \cos\mu \sin\gamma \cos\chi + \sin\mu \sin\chi & \cos\mu\sin\gamma\sin\chi-\sin\mu\cos\chi & \cos\mu\cos\gamma \end{bmatrix} \begin{bmatrix} \mathbf{i}_{h}\\ \mathbf{j}_{h}\\ \mathbf{k}_{h} \end{bmatrix} \end{medsize}$$

\end{document}


• Dear Bernard, Many thanks for your help. The former of your solutions is essentially what I was looking to achieve (only with a bit more space between the rows as suggested by 'egreg' below). Regards, Bob Mar 9 '17 at 10:21