# Wide equation - how to avoid the equation number on next line?

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}
$$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{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?

• (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 Commented Apr 21, 2016 at 13:33
• You could try changing \arraycolsep to a smaller value, say 4 pt. Commented Apr 21, 2016 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
Commented Apr 21, 2016 at 13:52

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{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{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

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}

$$\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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