11

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

\end{document}

But it does not seem to be working. enter image description here

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{equation}\begin{bmatrix} ... \end{bmatrix}\end{equation}\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
16

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}


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


\end{document}
16

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:

enter image description here

\documentclass[a4paper,12pt]{article}

\usepackage{mathtools}
\usepackage{lipsum}

\begin{document}

\lipsum[4]

\begin{equation}
    \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}
,\end{equation}
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}
  • 11
    +1 for making the document more readable rather than answering the question as asked:-) – David Carlisle Oct 27 '14 at 20:37
  • 3
    @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
7

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}{
  \begin{equation}
    E=mc^2
  \end{equation}
  }
\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.

4

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

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.