1

I have an equation with a large matrix that I want numbered as an equation. I use the code shown underneath:

\documentclass[12pt,a4paper]{report}
\usepackage{amsmath}
\begin{document}
\setcounter{MaxMatrixCols}{20}
\begin{equation}
    Y_{12} = 
\begin{bmatrix}
    -\frac{1}{x'_{d1}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 
    0 & -\frac{1}{x'_{d2}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 0 & -\frac{1}{x'_{d3}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 0 & 0 & -\frac{1}{x'_{d4}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 0 & 0 & 0 & -\frac{1}{x'_{d5}} & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d6}} & 0 & 0 & 0 & 0 & 0 \\
    0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d7}} & 0 & 0 & 0 & 0 \\
    0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d8}} & 0 & 0 & 0 \\
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d9}} & 0 & 0 \\
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d10}} & 0 \\
\end{bmatrix} \\
\end{equation}
\end{document}

This code works for smaller matrices. But with a large matrix the width of the equation seems to be wider than the \textwidth, as the equation numbering goes on the line below the matrix. How can I get the equation number at the same line as the equation?

3
  • (1) Welcome, (2) latex moves the eq number for a reason, if you fill theer is enough room for it, please provide us a fully compilable example that we can copy and test without having to add any code. (here for example we need to a a preamble for this to work
    – daleif
    Apr 21 '16 at 13:33
  • You could try changing \arraycolsep to a smaller value, say 4 pt.
    – Bernard
    Apr 21 '16 at 13:43
  • @daleif (1) Thank you, (2) I edited the code, I hope this is okay. (3) I also have another matrix that is so large that it goes outside the actual page. I would like to center it (regardless of whether the equation number is on the same line or not). Do you know how I do that?
    – kga
    Apr 21 '16 at 13:52
2

What are all those zeros good for, why not just write that this is a diagonal matrix with these entries:

\documentclass[12pt,a4paper]{report}
\usepackage{amsmath,mathtools}
\DeclareMathOperator\diag{diag}
\begin{document}
\begin{equation}
  \begin{split}
    Y_{12} = -\diag\Bigl( & \frac{1}{x'_{d1}}, \frac{1}{x'_{d2}},
    \frac{1}{x'_{d3}}, \frac{1}{x'_{d4}}, \frac{1}{x'_{d5}},
    \frac{1}{x'_{d6}},\frac{1}{x'_{d7}}, \frac{1}{x'_{d8}}, \frac{1}{x'_{d9}},
    \frac{1}{x'_{d10}} \Bigr)
  \end{split}
\end{equation}
\end{document}

For other matrix constructions one can break them up into smaller pieces, and write something like: To ease notation we first define ...

It is just a matter of not being locked into convention

enter image description here

1

Change the value of \arraycolsep or reduce the size of the font with the \medmath command from nccmath(about 80 % of displaystyle). You also can load geometry to have more sensible margins, if you don't use margin notes.

    \documentclass[12pt,a4paper]{report}
    \usepackage{mathtools, nccmath}
    \usepackage{showframe}
    \renewcommand*\ShowFrameLinethickness{.3pt}
    \setcounter{MaxMatrixCols}{20}

     \begin{document}

     \begin{equation}\setlength\arraycolsep{2pt}
        Y_{12} =
    \begin{bmatrix}
        -\frac{1}{x'_{d1}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & -\frac{1}{x'_{d2}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & -\frac{1}{x'_{d3}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & -\frac{1}{x'_{d4}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & -\frac{1}{x'_{d5}} & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d6}} & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d7}} & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d8}} & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d9}} & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d10}} & 0 \\
    \end{bmatrix}
    \end{equation}

 \begin{equation}\setlength\arraycolsep{4pt}
        Y_{12} =
        \medmath{\begin{bmatrix}
        -\frac{1}{x'_{d1}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & -\frac{1}{x'_{d2}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & -\frac{1}{x'_{d3}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & -\frac{1}{x'_{d4}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & -\frac{1}{x'_{d5}} & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d6}} & 0 & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d7}} & 0 & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d8}} & 0 & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d9}} & 0 & 0 \\
        0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{1}{x'_{d10}} & 0 \\
    \end{bmatrix}}
    \end{equation}

    \end{document}

enter image description here

0

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.