2

I'm writing my thesis and running into the following problem. I have a huge matrix (10 rows and 15 columns) which doesn't fit on a page. I would like LaTeX to split the matrix across lines, but right now it's running off the page. I've tried enabling "allowdisplaybreaks" from the amsmath package but it isn't having any effect. Any help is greatly appreciated!

Here is my LaTeX source:

\documentclass{article}
\usepackage{amsmath}
\allowdisplaybreaks

\begin{document}

\begin{align*}
B_u  = \begin{bmatrix}
-0.0629& 0.0629& -0.1819&  0.1819&       0&       0&       0&       0&       0&  0.0652&  0.0185&  0.0034&  0.0019& -0.0019& -0.0034\\
0.0107& 0.0107& -0.0676& -0.0676& -0.1455& -0.1455& -0.1494& -0.1494& -1.2860&       0&       0&  0.0013&  0.0035&  0.0035&  0.0013\\
-0.0142& 0.0142& -0.0128&  0.0128&       0&       0&       0&       0&       0& -0.1272& -0.0929&  0.0195&  0.0111& -0.0111& -0.0195\\         
0&      0&       0&       0&       0&       0&       0&       0& -0.3122&       0&       0&  0.1999&  0.1999&  0.1999&  0.1999\\
0&      0& -0.0098& -0.0098& -0.0071& -0.0071& -0.0074& -0.0074& -0.0676&       0&       0& -0.0004& -0.0004& -0.0004& -0.0004\\     
0&      0&       0&       0&       0&       0&       0&       0&       0&  0.0078&  0.0066&  0.0001&  0.0001& -0.0001& -0.0001\\
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&       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&       0&       0&       0&       0&       0&       0
\end{bmatrix}, 
\end{align*}

\end{document}

Here's a screenshot of what I'd like the matrix to look like on the page:enter image description here

2
  • 2
    Some suggestions: There's no need for align* here, \[...\] will do. Also, a sheer cut of a matrix across a page seems like a weird solution. How about rewriting the matrix in a different form? Or possibly boxing it in a float?
    – Werner
    Commented May 10, 2022 at 22:35
  • 1
    Welcome to TeX.SE.
    – Mico
    Commented May 10, 2022 at 23:18

2 Answers 2

2

Even if you render the (unnumbered) equation in landscape format -- say, with the help of the rotating package and its sidewaysfigure environment -- you'll still need to round the numbers from 4 to 3 decimal digits -- say, with the siunitx package and its S column type, which lets you perform rounding on the numbers -- and also reduce the amount of whitespace between columns (governed by the parameter \arraycolsep) in order to get the 15-column matrix to fit on a single page. (Aside: If, for some reason, you don't want to apply rounding and thus show all digits, you'll need to execute \footnotesize before entering math mode in order to get the equation to fit.)

The framelines around the printable part of the page are drawn by the showframe package.

enter image description here

\documentclass{article}
\usepackage{amsmath,
            rotating, % for 'sidewaysfigure' env.
            siunitx,  % for S column type
            showframe}

\begin{document}
\begin{sidewaysfigure}
\[
\setlength\arraycolsep{1.8pt} % default value: 5pt
B_u  = \left[  
\begin{array}{@{} *{15}{S[table-format=-1.3,
                          round-mode=places,
                          round-precision=3]} @{}}
-0.0629& 0.0629& -0.1819&  0.1819& 0& 0& 0& 0& 0&  0.0652&  0.0185&  0.0034&  0.0019& -0.0019& -0.0034\\
 0.0107& 0.0107& -0.0676& -0.0676& -0.1455& -0.1455& -0.1494& -0.1494& -1.2860& 0& 0&  0.0013&  0.0035&  0.0035&  0.0013\\
-0.0142& 0.0142& -0.0128&  0.0128& 0& 0& 0& 0& 0& -0.1272& -0.0929&  0.0195&  0.0111& -0.0111& -0.0195\\   
0& 0& 0& 0& 0& 0& 0& 0& -0.3122& 0& 0&  0.1999&  0.1999&  0.1999&  0.1999\\
0& 0& -0.0098& -0.0098& -0.0071& -0.0071& -0.0074& -0.0074& -0.0676& 0& 0& -0.0004& -0.0004& -0.0004& -0.0004\\     
0& 0& 0& 0& 0& 0& 0& 0& 0& 0.0078& 0.0066& 0.0001& 0.0001& -0.0001& -0.0001\\
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& 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& 0& 0& 0& 0& 0& 0
\end{array} 
\right]
\]
\end{sidewaysfigure}
\end{document}
1
+50

I'm not sure this is a good idea, but it accomplishes what you want. You can use the trimclip package to literally cut your huge matrix into two pieces. Then use the multline environment to place the matrix pieces on the page. I put the huge matrix into a macro \hugematrix since it has to be called twice when the two pieces are created.

The syntax for \clipbox* is as follows:

\clipbox*{{<llx>} {<lly>} {<urx>} {<ury>}}{<content to be clipped>}

where <llx> and <lly> are the x and y coordinates of the lower left corner of the box you want to keep from <content> and <urx> and <ury> are the upper right coordinates. You can use \height, \width and \depth (or multiples of those) to reference the height (above the baseline), depth (below baseline) and width of the content. To avoid clipping a small portion of the edge, you need slightly more than \height and \depth.

In your example, I used

\clipbox*{0pt {-1.1\depth} {.46\width} {1.1\height}}{\hugematrix}

to clip from the lower left (10% below depth) to a spot a little less than half the width (chosen by trial and error to land between columns). That's the left half. The right half is

\clipbox*{{.46\width} {-1.1\depth} {\width} {1.1\height}}{\hugematrix}

But even in two pieces, the matrix is too wide for the page. Here is what the matrix looks like clipped in two:

enter image description here

As you can see, the right half is wider than \textwidth, and the left half is nearly as wide. There is no hope of fitting this on two lines without either going into the margins or making the matrix smaller.

One way to make the matrix smaller is to use smallmatrix* from the mathtools package (which has an option for right-alignment of the columns).

enter image description here

Here is the code using smallmatrix*:

\documentclass{article}

\usepackage{mathtools,trimclip,lipsum}
\setcounter{MaxMatrixCols}{20}
\newcommand{\hugematrix}{$\left[\begin{smallmatrix*}[r]
-0.0629& 0.0629& -0.1819&  0.1819&       0&       0&       0&       0&       0&  0.0652&  0.0185&  0.0034&  0.0019& -0.0019& -0.0034\\
0.0107& 0.0107& -0.0676& -0.0676& -0.1455& -0.1455& -0.1494& -0.1494& -1.2860&       0&       0&  0.0013&  0.0035&  0.0035&  0.0013\\
-0.0142& 0.0142& -0.0128&  0.0128&       0&       0&       0&       0&       0& -0.1272& -0.0929&  0.0195&  0.0111& -0.0111& -0.0195\\         
0&      0&       0&       0&       0&       0&       0&       0& -0.3122&       0&       0&  0.1999&  0.1999&  0.1999&  0.1999\\
0&      0& -0.0098& -0.0098& -0.0071& -0.0071& -0.0074& -0.0074& -0.0676&       0&       0& -0.0004& -0.0004& -0.0004& -0.0004\\     
0&      0&       0&       0&       0&       0&       0&       0&       0&  0.0078&  0.0066&  0.0001&  0.0001& -0.0001& -0.0001\\
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&       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&       0&       0&       0&       0&       0&       0
\end{smallmatrix*}\right]$}

\begin{document}

\lipsum[1]
\begin{multline*}
B_u  = \clipbox*{0pt {-1.1\depth} {.53\width} {1.1\height}}{\hugematrix}\\ 
\clipbox*{{.53\width} {-1.1\depth} {\width} {1.1\height}}{\hugematrix}
\end{multline*}

\lipsum[2]
\end{document}

If you find smallmatrix too small, you could use \scalebox to scale the pieces of the huge matrix small enough to fit. Here it is at 90%, which just barely fits:

enter image description here

The code is here:

\documentclass{article}

\usepackage{mathtools,trimclip,lipsum}
\setcounter{MaxMatrixCols}{20}
\newcommand{\hugematrix}{$\begin{bmatrix*}[r]
-0.0629& 0.0629& -0.1819&  0.1819&       0&       0&       0&       0&       0&  0.0652&  0.0185&  0.0034&  0.0019& -0.0019& -0.0034\\
0.0107& 0.0107& -0.0676& -0.0676& -0.1455& -0.1455& -0.1494& -0.1494& -1.2860&       0&       0&  0.0013&  0.0035&  0.0035&  0.0013\\
-0.0142& 0.0142& -0.0128&  0.0128&       0&       0&       0&       0&       0& -0.1272& -0.0929&  0.0195&  0.0111& -0.0111& -0.0195\\         
0&      0&       0&       0&       0&       0&       0&       0& -0.3122&       0&       0&  0.1999&  0.1999&  0.1999&  0.1999\\
0&      0& -0.0098& -0.0098& -0.0071& -0.0071& -0.0074& -0.0074& -0.0676&       0&       0& -0.0004& -0.0004& -0.0004& -0.0004\\     
0&      0&       0&       0&       0&       0&       0&       0&       0&  0.0078&  0.0066&  0.0001&  0.0001& -0.0001& -0.0001\\
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&       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&       0&       0&       0&       0&       0&       0
\end{bmatrix*}$}

\begin{document}

\lipsum[1]
\begin{multline*}
B_u  = \scalebox{.9}{\clipbox*{0pt {-1.1\depth} {.46\width} {1.1\height}}{\hugematrix}}\\ 
\scalebox{.9}{\clipbox*{{.46\width} {-1.1\depth} {\width} {1.1\height}}{\hugematrix}}
\end{multline*}

\lipsum[2]
\end{document}

Here its is scaled to 80% with a different clip:

enter image description here

\begin{multline*}
B_u  = \scalebox{.8}{\clipbox*{0pt {-1.1\depth} {.53\width} {1.1\height}}{\hugematrix}}\\ 
\scalebox{.8}{\clipbox*{{.53\width} {-1.1\depth} {\width} {1.1\height}}{\hugematrix}}
\end{multline*}
5
  • Thanks, this is helpful. I replaced smallmatrix with bmatrix because smallmatrix was looking too small on the page. It looks ok now, expect that the right half of the matrix (which appears below the left half of the matrix on the page) is aligned left, when I'd prefer it to be aligned right. Do you know how to fix it? Also can you explain how your solution works? What do the parameters (e.g. -1.1.depth, 0.53width, etc) mean?
    – Gautam
    Commented May 14, 2022 at 19:24
  • @Gautam: I edited my response to explain the parameters of \clipbox and give you some another option for making the matrix fit. The reason your right half looks left justified is because it it too wide to fit on the page. So the right margin is used as overfull space. You'll need to make the matrix smaller one way or another to get the look you want.
    – Sandy G
    Commented May 14, 2022 at 20:26
  • Thanks, this is super helpful! I'm using scalebox. One last question: I have another matrix definition underneath, but this matrix is much smaller and easily fits on the page. I could just write the equation in standard way, e.g. $X = \begin{bmatrix} ... \end{bmatrix}$; however, the font size is noticeably bigger than the font above it, in the scalebox. How can I rescale the second matrix to match the first? I tried using your technique, but that put the small matrix far away from the definition, e.g. it looked like X = [huge blank space] [small matrix at right margin].
    – Gautam
    Commented May 15, 2022 at 6:09
  • @Gautam: $\quad X=\scalebox{.8}{$\begin{bmatrix}1&0\\0&1\end{bmatrix}$}$ works. Don't put the short line inside a multline environment since you're not splitting it over two lines. Multline inserts a \quad space at the left so you need the same space in your short line to match.
    – Sandy G
    Commented May 15, 2022 at 14:06
  • Hi Sandy, thanks so much for all of your help. I am awarding you the bounty.
    – Gautam
    Commented May 15, 2022 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .