# sideways for equation (a big matrix)

I hope to use sideways for my big matrix, like this and this. It looks straight forward. But it's not working for me.

\documentclass[a4paper,12pt]{article}

\usepackage{amsmath}
\usepackage{rotating}

\begin{document}

\begin{sideways}
$$\begin{bmatrix} \frac{1}{\phi_1} & \frac{1}{\phi_1} & \frac{1}{\phi_1} & \frac{1}{\phi_1} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & 0 & 0 & 0 \\ 0 & 0 & \frac{1}{\phi_3} & \frac{1}{\phi_3} & 0 & \frac{1}{\phi_3} & \frac{1}{\phi_3} & \frac{1}{\phi_3} & \frac{1}{\phi_3} & 0 \\ 0 & 0 & 0 & \frac{1}{\phi_4} & 0 & 0 & \frac{1}{\phi_4} & 0 & \frac{1}{\phi_4} & \frac{1}{\phi_4} \\ \frac{1}{1+\mathrm{e}^{a2+m}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & \frac{1}{1+\mathrm{e}^{a3}} & \frac{-1}{1+\mathrm{e}^{-a3}} & \frac{-1}{1+\mathrm{e}^{-a3}} & \frac{1}{1+\mathrm{e}^{a3+m}} & \frac{-1}{1+\mathrm{e}^{-(a3+m)}} & \frac{-1}{1+\mathrm{e}^{-(a3+m)}} & 0 & 0 & 0 \\ 0 & 0 & \frac{1}{1+\mathrm{e}^{a4}} & \frac{-1}{1+\mathrm{e}^{-a4}} & 0 & \frac{1}{1+\mathrm{e}^{a4}} & \frac{-1}{1+\mathrm{e}^{-a4}} & \frac{1}{1+\mathrm{e}^{a4+m}} & \frac{-1}{1+\mathrm{e}^{-(a4+m)}} & 0 \\ 0 & 0 & 0 & \frac{1}{1+\mathrm{e}^{a5}} & 0 & 0 & \frac{1}{1+\mathrm{e}^{a5}} & 0 & \frac{1}{1+\mathrm{e}^{a5}} & \frac{1}{1+\mathrm{e}^{a5+m}} \\ \frac{1}{1+\mathrm{e}^{a2+m}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{1}{1+\mathrm{e}^{a3+m}} & \frac{-1}{1+\mathrm{e}^{-(a3+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{1}{1+\mathrm{e}^{a4+m}} & \frac{-1}{1+\mathrm{e}^{-(a4+m)}} & \frac{1}{1+\mathrm{e}^{a5+m}} \end{bmatrix}$$
\end{sideways}

\end{document}


But it does not seem to be working.

I would expect that it takes maths environments?

• Compared to Stefan's answer, you're missing a minipage environment. So it should go \begin{sideways}\begin{minipage}{\textheight}$$\begin{bmatrix} ... \end{bmatrix}$$\end{minipage}\end{sideways} – Mike Renfro Oct 27 '14 at 19:49
• Yes, I just noticed! But I did not think it was necessary. Thanks! – Chen Stats Yu Oct 27 '14 at 19:59

rotating package's sideways environment is really just for compatibility with the LaTex2.09 version, it is just a thin wrapper around \rotatebox giving the old syntax.

But box commands take you out of math mode so you need \$ to get back in:

\documentclass[a4paper,12pt]{article}

\usepackage{amsmath}
\usepackage{graphicx}

\begin{document}

$$\rotatebox{90}{\begin{bmatrix} \frac{1}{\phi_1} & \frac{1}{\phi_1} & \frac{1}{\phi_1} & \frac{1}{\phi_1} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & 0 & 0 & 0 \\ 0 & 0 & \frac{1}{\phi_3} & \frac{1}{\phi_3} & 0 & \frac{1}{\phi_3} & \frac{1}{\phi_3} & \frac{1}{\phi_3} & \frac{1}{\phi_3} & 0 \\ 0 & 0 & 0 & \frac{1}{\phi_4} & 0 & 0 & \frac{1}{\phi_4} & 0 & \frac{1}{\phi_4} & \frac{1}{\phi_4} \\ \frac{1}{1+\mathrm{e}^{a2+m}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & \frac{1}{1+\mathrm{e}^{a3}} & \frac{-1}{1+\mathrm{e}^{-a3}} & \frac{-1}{1+\mathrm{e}^{-a3}} & \frac{1}{1+\mathrm{e}^{a3+m}} & \frac{-1}{1+\mathrm{e}^{-(a3+m)}} & \frac{-1}{1+\mathrm{e}^{-(a3+m)}} & 0 & 0 & 0 \\ 0 & 0 & \frac{1}{1+\mathrm{e}^{a4}} & \frac{-1}{1+\mathrm{e}^{-a4}} & 0 & \frac{1}{1+\mathrm{e}^{a4}} & \frac{-1}{1+\mathrm{e}^{-a4}} & \frac{1}{1+\mathrm{e}^{a4+m}} & \frac{-1}{1+\mathrm{e}^{-(a4+m)}} & 0 \\ 0 & 0 & 0 & \frac{1}{1+\mathrm{e}^{a5}} & 0 & 0 & \frac{1}{1+\mathrm{e}^{a5}} & 0 & \frac{1}{1+\mathrm{e}^{a5}} & \frac{1}{1+\mathrm{e}^{a5+m}} \\ \frac{1}{1+\mathrm{e}^{a2+m}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{1}{1+\mathrm{e}^{a3+m}} & \frac{-1}{1+\mathrm{e}^{-(a3+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{1}{1+\mathrm{e}^{a4+m}} & \frac{-1}{1+\mathrm{e}^{-(a4+m)}} & \frac{1}{1+\mathrm{e}^{a5+m}} \end{bmatrix}}$$

\end{document}


I would much more prefer to fit the matrix in (with my Copy Editor hat on). A lot of data is repeated, which gives some space for manipulation:

\documentclass[a4paper,12pt]{article}

\usepackage{mathtools}
\usepackage{lipsum}

\begin{document}

\lipsum[4]

$$\begin{bmatrix} \phi_1^{-1} & \phi_1^{-1} & \phi_1^{-1} & \phi_1^{-1} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & \phi_2^{-1} & \phi_2^{-1} & \phi_2^{-1} & \phi_2^{-1} & \phi_2^{-1} & \phi_2^{-1} & 0 & 0 & 0 \\ 0 & 0 & \phi_3^{-1} & \phi_3^{-1} & 0 & \phi_3^{-1} & \phi_3^{-1} & \phi_3^{-1} & \phi_3^{-1} & 0 \\ 0 & 0 & 0 & \phi_4^{-1} & 0 & 0 & \phi_4^{-1} & 0 & \phi_4^{-1} & \phi_4^{-1} \\ f(b_2) & g(b_2) & g(b_2) & g(b_2) & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & f(a_3) & g(a_3) & g(a_3) & f(b_3) & g(b_3) & g(b_3) & 0 & 0 & 0 \\ 0 & 0 & f(a_4) & g(a_4) & 0 & f(a_4) & g(a_4) & f(b_4) & g(b_4) & 0 \\ 0 & 0 & 0 & f(a_5) & 0 & 0 & f(a_5) & 0 & f(a_5) & f(b_5) \\ f(b_2) & g(b_2) & g(b_2) & g(b_2) & f(b_3) & g(b_3) & g(b_2) & f(b_4) & g(b_4) & f(b_5) \end{bmatrix} ,$$
where
$f(a) \coloneqq \frac{1}{1+\mathrm{e}^a} ,\quad g(a) \coloneqq \frac{-1}{1+\mathrm{e}^{-a}} \quad\text{and}\quad b_i \coloneqq a_i+m .$

\lipsum[13]

\end{document}

• +1 for making the document more readable rather than answering the question as asked:-) – David Carlisle Oct 27 '14 at 20:37
• @DavidCarlisle Answering questions as they're asked is no fun :P – yo' Oct 27 '14 at 20:41
• This was thought about. However, my purpose was to illustrate a specific task. So can't really use this "shorthand". – Chen Stats Yu Oct 27 '14 at 22:23
• @ChenStatsYu Then I would really like to know what the task is that makes rotating a matrix (and confusing the reader) better than substituting parts like this. It would have been even better to simply transpose the matrix than to rotate it. Caring to come to the chat at chat.stackexchange.com/rooms/41/tex-latex-and-friends please? :) – yo' Oct 27 '14 at 22:43

The contents of a sideways environment are stored in an \hbox for later processing. Inside an \hbox, display math is not recognized. (TeX calls this "inner horizontal mode"). One needs to switch to "vertical mode" by wrapping the contents in a \parbox or a minipage environment. Thus

\begin{sideways}
\parbox{8in}{
$$E=mc^2$$
}
\end{sideways}


Note that your matrix, when turned sideways, is too tall for a normal page size. It will still be placed, but somehow it ends up on the next page unless it fits on one page.

As an alternative to sideways as David solves for you. You could consider landscape from the lscape package, which respects math mode.

\documentclass[a4paper,12pt]{article}

\usepackage{amsmath}
\usepackage{lscape}

\begin{document}

\begin{landscape}
$$\begin{bmatrix} \frac{1}{\phi_1} & \frac{1}{\phi_1} & \frac{1}{\phi_1} & \frac{1}{\phi_1} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & \frac{1}{\phi_2} & 0 & 0 & 0 \\ 0 & 0 & \frac{1}{\phi_3} & \frac{1}{\phi_3} & 0 & \frac{1}{\phi_3} & \frac{1}{\phi_3} & \frac{1}{\phi_3} & \frac{1}{\phi_3} & 0 \\ 0 & 0 & 0 & \frac{1}{\phi_4} & 0 & 0 & \frac{1}{\phi_4} & 0 & \frac{1}{\phi_4} & \frac{1}{\phi_4} \\ \frac{1}{1+\mathrm{e}^{a2+m}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & \frac{1}{1+\mathrm{e}^{a3}} & \frac{-1}{1+\mathrm{e}^{-a3}} & \frac{-1}{1+\mathrm{e}^{-a3}} & \frac{1}{1+\mathrm{e}^{a3+m}} & \frac{-1}{1+\mathrm{e}^{-(a3+m)}} & \frac{-1}{1+\mathrm{e}^{-(a3+m)}} & 0 & 0 & 0 \\ 0 & 0 & \frac{1}{1+\mathrm{e}^{a4}} & \frac{-1}{1+\mathrm{e}^{-a4}} & 0 & \frac{1}{1+\mathrm{e}^{a4}} & \frac{-1}{1+\mathrm{e}^{-a4}} & \frac{1}{1+\mathrm{e}^{a4+m}} & \frac{-1}{1+\mathrm{e}^{-(a4+m)}} & 0 \\ 0 & 0 & 0 & \frac{1}{1+\mathrm{e}^{a5}} & 0 & 0 & \frac{1}{1+\mathrm{e}^{a5}} & 0 & \frac{1}{1+\mathrm{e}^{a5}} & \frac{1}{1+\mathrm{e}^{a5+m}} \\ \frac{1}{1+\mathrm{e}^{a2+m}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{1}{1+\mathrm{e}^{a3+m}} & \frac{-1}{1+\mathrm{e}^{-(a3+m)}} & \frac{-1}{1+\mathrm{e}^{-(a2+m)}} & \frac{1}{1+\mathrm{e}^{a4+m}} & \frac{-1}{1+\mathrm{e}^{-(a4+m)}} & \frac{1}{1+\mathrm{e}^{a5+m}} \end{bmatrix}$$
\end{landscape}

\end{document}