# 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{equation}
\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{equation}

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

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

\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. – Bob1986 Mar 9 '17 at 10:47
• @Bob1986 Sure, but you need “phantoms” and the input is quite complicated. – egreg 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. – Bob1986 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{equation}
\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}
\end{equation}

\begin{equation}\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{equation}

\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 – Bob1986 Mar 9 '17 at 10:21
{"ft_lang_label":"__label__en","ft_lang_prob":0.63629186,"math_prob":0.99897575,"size":1168,"snap":"2020-24-2020-29","text_gpt3_token_len":388,"char_repetition_ratio":0.17611684,"word_repetition_ratio":0.0,"special_character_ratio":0.29195204,"punctuation_ratio":0.06465517,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":1.0000048,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,2,null,2,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-06-04T21:02:51Z\",\"WARC-Record-ID\":\"<urn:uuid:96aaad5c-359a-4a85-b056-0e9529d88762>\",\"Content-Length\":\"159494\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:814fee5f-119a-4b71-b437-b29f0f282de1>\",\"WARC-Concurrent-To\":\"<urn:uuid:4e156878-630f-4ac3-b1c6-8904492e6e9c>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://tex.stackexchange.com/questions/357583/split-long-expression-inside-bmatrix-environment\",\"WARC-Payload-Digest\":\"sha1:TNKWIAICUXIQAAQMYEYS4UGFBDW57Y6E\",\"WARC-Block-Digest\":\"sha1:GXDKD7F3CEW34N5CM67R22GCEDLJEWX6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-24/CC-MAIN-2020-24_segments_1590347458095.68_warc_CC-MAIN-20200604192256-20200604222256-00481.warc.gz\"}"}