# How to get my matrix to fit inside the width of the text block?

New to LaTeX here. This is what I have so far:

\documentclass[11pt]{article}
\usepackage{amsmath}

\begin{document}

$$A = \begin{bmatrix} 0 & \cos(\theta_{1})\sin(\phi_{1})\sin(\tau_{1}) & \cos(\theta_{2})\sin(\phi_{2})\sin(\tau_{3}) & \cos(\theta_{4})\sin(\phi_{4})\sin(\tau_{4}) & \cos(\theta_{5})\sin(\phi_{5})\sin(\tau_{5}) & \cos(\theta_{6})\sin(\phi_{6})\sin(\tau_{6}) & \cos(\theta_{7})\sin(\phi_{7})\sin(\tau_{7}) & \cos(\theta_{8})\sin(\phi_{8})\sin(\tau_{8}) & \cos(\theta_{8})\sin(\phi_{8})\sin(\tau_{8}) & \cos(\theta_{9})\sin(\phi_{9})\sin(\tau_{9}) \\ 0 & \sin(\theta_{1})\sin(\phi_{1})\sin(\tau_{1}) & \sin(\theta_{2})\sin(\phi_{2})\sin(\tau_{2}) & \sin(\theta_{3})\sin(\phi_{3})\sin(\tau_{3}) & \sin(\theta_{4})\sin(\phi_{4})\sin(\tau_{4}) & \sin(\theta_{5})\sin(\phi_{5})\sin(\tau_{5}) & \sin(\theta_{6})\sin(\phi_{6})\sin(\tau_{6}) & \sin(\theta_{7})\sin(\phi_{7})\sin(\tau_{7}) & \sin(\theta_{8})\sin(\phi_{8})\sin(\tau_{8}) & \sin(\theta_{9})\sin(\phi_{9})\sin(\tau_{9}) \\ 0 & \cos(\phi_{1})\sin(\tau_{1}) & \cos(\phi_{2})\sin(\tau_{2}) & \cos(\phi_{3})\sin(\tau_{3}) & \cos(\phi_{4})\sin(\tau_{4}) & \cos(\phi_{5})\sin(\tau_{5}) & \cos(\phi_{6})\sin(\tau_{6}) & \cos(\phi_{7})\sin(\tau_{7}) & \cos(\phi_{8})\sin(\tau_{8}) & \cos(\phi_{9})\sin(\tau_{9}) \\ 1 & \sin(\tau_{1}) & \sin(\tau_{2}) & \sin(\tau_{3}) & \sin(\tau_{4}) & \sin(\tau_{5}) & \sin(\tau_{6}) & \sin(\tau_{7}) & \sin(\tau_{8}) & \sin(\tau_{9}) \\ \end{bmatrix}$$
\end{document}


However, this won't fit inside the width of the text block. How do I go about fixing this? Is there a way I can adjust the font size or the overall size of the matrix?

• Even with very small font size I don't think it would be a good format. What about giving names for matrix entries? For example, \cos(\theta_{1})\sin(\phi_{1})\sin(\tau_{1}) could be a_1 and then 1st row would be from a_1 to a_9. – Sigur May 10 at 1:51

I propose the following:

\documentclass[11pt]{article}
\usepackage{amsmath}

\begin{document}For $i=1,\dots,9$ write
\begin{align*}
a_i&=\cos(\theta_{i})\sin(\phi_{i})\sin(\tau_{i}),\\ b_i&=\sin(\theta_{i})\sin(\phi_{i})\sin(\tau_{i}),\\ c_i&=\cos(\phi_{i})\sin(\tau_{i})\\
d_i&=\sin(\tau_{i}).
\end{align*}
Then,
$A = \begin{bmatrix} 0 &a_1& \cdots & a_9 \\ 0 &b_1& \cdots & b_9 \\ 0 &c_1& \cdots & c_9 \\ 1 &d_1& \cdots & d_9 \\ \end{bmatrix}$

Alternatively,
$A = \begin{bmatrix} 0 &\cos(\theta_{1})\sin(\phi_{1})\sin(\tau_{1})& \cdots & \cos(\theta_{9})\sin(\phi_{9})\sin(\tau_{9}) \\ 0 &\sin(\theta_{1})\sin(\phi_{1})\sin(\tau_{1})& \cdots & \sin(\theta_{9})\sin(\phi_{9})\sin(\tau_{9}) \\ 0 &\cos(\phi_{1})\sin(\tau_{1})& \cdots & \cos(\phi_{9})\sin(\tau_{9}) \\ 1 &\sin(\tau_{1})& \cdots & \sin(\tau_{9}) \\ \end{bmatrix}.$
\end{document}


Instead of trying to display a 4x10 matrix with wide entries in 8 of the 10 columns, I suggest you display its transpose, i.e., a 10x4 matrix.

Moreover, since the cells in rows 2 thru 10 of the transposed matrix differ only in their row indices, I suggest you typeset them in a loop. This may be accomplished in a straightforward manner if you're free to use LuaLaTeX. The Lua function takes 1 argument, the number of rows to be printed. Thus, if you decide to switch from 9 to, say, 19 rows, all you would need to do is change the argument with with fancy_rows is called.

Observe that I've omitted all 9*9=81 pairs of parentheses around the \theta, \phi, and \tau terms. (If you must use parentheses, it's very easy to insert them in the Lua for loop.)

%%% Must be compiled under LuaLaTeX
\documentclass[11pt]{article}
\usepackage{amsmath} % for 'bmatrix' environment
\usepackage{luacode} % for 'luacode' environment
\begin{luacode}

function fancy_rows ( N )
for i=1,N do
tex.sprint ( "\\cos\\theta_{" ..i.. "}\\sin\\phi_{" ..i.. "}\\sin\\tau_{" ..i.. "}&" )
tex.sprint ( "\\cos\\theta_{" ..i.. "}\\sin\\phi_{" ..i.. "}\\sin\\tau_{" ..i.. "}&" )
tex.sprint ( "\\cos\\phi_{"   ..i.. "}\\sin\\tau_{" ..i.. "}&" )
tex.sprint ( "\\sin\\tau_{"   ..i.. "}" )
if i<N then tex.sprint ( "\\\\" ) end
end
end

\end{luacode}

\begin{document}
$A' = \begin{bmatrix} 0 & 0 & 0 & 1 \\ \directlua { fancy_rows(9) } \end{bmatrix}$
\end{document}