Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to display the matrix in latex document using below code.But the right side of the matrix is not getting displayed completely.Please check this.

\[
 M=
\left[ {\begin{array}{cccccccccccccccccccccccc}
 0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 0.9 & 0 & 0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 1.2 & 0 & 0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 0.9 & 0\\
 0 & 0.47 & 0 & 0 & 0.47 & 0 & 0 & 0.95 & 0 & 0 & 0.47 & 0 & 0 & 0.47 & 0 & 0 & 0.95 & 0 & 0 & 0.47 & 0 & 0 & 0.47 & 0\\
 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0 & 1.4\\
 0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0\\
 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.07 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.07 & 0 & 0 & 0\\
 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0\\
 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0\\
\end{array} } \right]
\]  
share|improve this question

migrated from stackoverflow.com Sep 2 '12 at 12:16

This question came from our site for professional and enthusiast programmers.

4  
You can (1) reduce the font size; (2) rescale the entire output and make it smaller; or (3) reduce the \arraycolsep. It depends on your document or output requirements. Also, rather use \begin{array}{*{24}{c}} - it's much less error prone. –  Werner Sep 2 '12 at 6:42
    
you may also think of using \begin{smallmatrix}…\end{smallmatrix} –  epsilonhalbe Sep 2 '12 at 8:32
    
another possibility is to pack the array into a \scalebox as provided by the graphicx package. however, that could become almost unreadable. better, i think, to make this into a figure and set it landscape. –  barbara beeton Sep 2 '12 at 17:10

1 Answer 1

up vote 4 down vote accepted

The following code shows three possible options:

  1. Using \resizebox to automatically scale the matrix to have width equal to \textwidth (since the matrix is really large, the resulting matrix can be difficult to read).

  2. Using \resizebox but previously increasing the margins using, for example, the \adjustwidth environment from the changepage package; this improves readability, but margins have been partially increased nad this might not be desired.

  3. Using the \resizebox and the sidewaysfigure environment from the rotating package to put the matrix in landscape orientation in a page of its own. This seems to be the best solution.

    \documentclass{article}
    \usepackage{amsmath}
    \usepackage{graphicx}
    \usepackage{changepage}
    \usepackage{rotating}
    
    \begin{document}
    
    % requires the graphicx package
    \[
    \resizebox{\textwidth}{!}{%
     $M=
    \left[ {\begin{array}{*{24}{c}}
     0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 0.9 & 0 & 0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 1.2 & 0 & 0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 0.9 & 0\\
     0 & 0.47 & 0 & 0 & 0.47 & 0 & 0 & 0.95 & 0 & 0 & 0.47 & 0 & 0 & 0.47 & 0 & 0 & 0.95 & 0 & 0 & 0.47 & 0 & 0 & 0.47 & 0\\
     0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0 & 1.4\\
     0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.07 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.07 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0\\
    \end{array} } \right]$
     }
    \]
    
    % requires the changepage package
    \begin{adjustwidth}{-3cm}{-3cm}
    \[
    \resizebox{\dimexpr\textwidth+6cm\relax}{!}{%
     $M=
    \left[ {\begin{array}{*{24}{c}}
     0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 0.9 & 0 & 0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 1.2 & 0 & 0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 0.9 & 0\\
     0 & 0.47 & 0 & 0 & 0.47 & 0 & 0 & 0.95 & 0 & 0 & 0.47 & 0 & 0 & 0.47 & 0 & 0 & 0.95 & 0 & 0 & 0.47 & 0 & 0 & 0.47 & 0\\
     0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0 & 1.4\\
     0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.07 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.07 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0\\
    \end{array} } \right]$
     }
    \]
    \end{adjustwidth}
    
    % requires the rotating package
    \begin{sidewaysfigure}
    \[
    \resizebox{\textheight}{!}{%
     $M=
    \left[ {\begin{array}{*{24}{c}}
     0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 0.9 & 0 & 0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 1.2 & 0 & 0.3 & 0 & 0.6 & 0 & 0.3 & 0 & 0.9 & 0\\
     0 & 0.47 & 0 & 0 & 0.47 & 0 & 0 & 0.95 & 0 & 0 & 0.47 & 0 & 0 & 0.47 & 0 & 0 & 0.95 & 0 & 0 & 0.47 & 0 & 0 & 0.47 & 0\\
     0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0.7 & 0 & 0 & 0 & 0 & 0 & 1.4\\
     0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0 & 0 & 0 & 0.9 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.07 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.07 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0 & 0 & 0 & 0 & 0\\
     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1.38 & 0 & 0\\
    \end{array} } \right]$
     }
    \]
    
    \end{sidewaysfigure}
    
    \end{document}
    

The result showing the three options for comparison:

enter image description here

share|improve this answer
1  
surely better to use sidewaystable (rather than ...figure), so that the caption comes out right (even though op didn't mention a caption) –  wasteofspace Sep 3 '12 at 6:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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