[Tex/LaTex] Make matrix inside equation fit the page width in LyX

boxeslyxmatrices

I have a matrix that is a bit too wide to fit inside my page width.

After reading a lot of different answers on the Internet, none really related to LyX, I came up with these three different solutions, all of them involve inserting an ERT (raw LaTeX code, in this case all the lines before \begin{equation} and after \end{equation}). Here is the image:

output

I don't know if other possibilities also work and which are the advantages or disadvantages, from each method.

The LaTeX source for all this is:

\noindent\makebox[\textwidth]{%
\tiny%
\begin{minipage}[t]{1\columnwidth}%
\begin{equation}
Q=\begin{pmatrix}
0.00301472 & -0.0961879 & -0.00897697 & 0.0389941 & -0.860642 & 0.0131329 & -4.73786 & -0.00552858\\
-0.028584 & 0.615003 & 0.111671 & -0.371008 & 4.94379 & -0.138279 & 20.3258 & 0.0512362\\
0.0132728 & -0.345125 & -0.0701132 & 0.115389 & -3.11777 & 0.102871 & -16.9949 & -0.0408223\\
2.91757 & 1.03545 & -5.16595 & 1.69976 & -22.1649 & 4.33453 & 120.513 & -1.35074\\
0.867566 & 2.92363 & -1.14174 & 3.4356 & -2.96193 & 1.91413 & -113.348 & -0.684269
\end{pmatrix}
\end{equation}
%
\end{minipage}}

\resizebox{\textwidth}{!}{%
\tiny%
\begin{minipage}[t]{1\columnwidth}%
\begin{equation}
Q_{ij}=\left(\begin{array}{cccccccc}
0.00301472 & -0.0961879 & -0.00897697 & 0.0389941 & -0.860642 & 0.0131329 & -4.73786 & -0.00552858\\
-0.028584 & 0.615003 & 0.111671 & -0.371008 & 4.94379 & -0.138279 & 20.3258 & 0.0512362\\
0.0132728 & -0.345125 & -0.0701132 & 0.115389 & -3.11777 & 0.102871 & -16.9949 & -0.0408223\\
2.91757 & 1.03545 & -5.16595 & 1.69976 & -22.1649 & 4.33453 & 120.513 & -1.35074\\
0.867566 & 2.92363 & -1.14174 & 3.4356 & -2.96193 & 1.91413 & -113.348 & -0.684269
\end{array}\right)
\end{equation}
%
\end{minipage}}

\noindent%
\begin{minipage}[t]{1\textwidth}%
\tiny
\begin{equation}
Q=\begin{pmatrix}
0.00301472 & -0.0961879 & -0.00897697 & 0.0389941 & -0.860642 & 0.0131329 & -4.73786 & -0.00552858\\
-0.028584 & 0.615003 & 0.111671 & -0.371008 & 4.94379 & -0.138279 & 20.3258 & 0.0512362\\
0.0132728 & -0.345125 & -0.0701132 & 0.115389 & -3.11777 & 0.102871 & -16.9949 & -0.0408223\\
2.91757 & 1.03545 & -5.16595 & 1.69976 & -22.1649 & 4.33453 & 120.513 & -1.35074\\
0.867566 & 2.92363 & -1.14174 & 3.4356 & -2.96193 & 1.91413 & -113.348 & -0.684269
\end{pmatrix}
\end{equation}
%
\end{minipage}

Is there a simpler way of doing this in LyX, for example without using the \tiny command and inserting boxes inside boxes? Can't LaTeX simply determine when a matrix is too big and rescale it to fit the page?

This is how it looks like in the output: 2

Best Answer

You may want to consider whether it's absolutely necessary to show up to 8 digits after the decimal point in order to convey the message you intend to send. If you can make do with, say, 4 digits after the decimal, you could use the siunitx package and its S column type to show the matrix in the form shown below. Note that it's not necessary to round and truncate the numbers by hand; siunitx will take of this job for you.

Incidentally, if the S column type is used, all numbers are aligned on the decimal points -- presumably a desirable thing, right? Note that with these modifications, it's not necessary at all to reduce the font size.

enter image description here

\documentclass{article}
\usepackage[margin=1in]{geometry} %
\usepackage{siunitx}
\sisetup{round-mode=places,       % enable rounding
         round-precision=4,       % amounts of digits for rounding
         table-format=-1.4}       % default numeric format
\begin{document}
\begin{equation}
Q_{ij}=\left(
\begin{array}{*{4}{S}
              S[table-format=3.4]
              S 
              S[table-format=4.4] 
              S} % non-default values for "table-format" for columns 5 and 7
   0.00301472 & -0.0961879 & -0.00897697 & 0.0389941 & -0.860642 & 0.0131329 & -4.73786 & -0.00552858\\
   -0.028584 & 0.615003 & 0.111671 & -0.371008 & 4.94379 & -0.138279 & 20.3258 & 0.0512362\\
   0.0132728 & -0.345125 & -0.0701132 & 0.115389 & -3.11777 & 0.102871 & -16.9949 & -0.0408223\\
   2.91757 & 1.03545 & -5.16595 & 1.69976 & -22.1649 & 4.33453 & 120.513 & -1.35074\\
   0.867566 & 2.92363 & -1.14174 & 3.4356 & -2.96193 & 1.91413 & -113.348 & -0.684269
\end{array}
\right)
\end{equation}
\end{document}