# A long equation: how to adapt the font size to the page width?

I would like to reduce the size of the following equation just exactly as needed in order to fit the page. Is there some sort of command to adapt the font size to the page width?

Here's my latex:

$$d\left(\begin{array}{c} D(t) \\ \Pi(t) \\ \Theta(t) \end{array}\right) = \left(\begin{array}{ccc} -\alpha_{D} & 1 & 0 \\ 0 & -\alpha_{\Pi} & 0 \\ 0 & 0 & -\alpha_{\Theta} \end{array}\right) \left(\begin{array}{c} D(t) \\ \Pi(t) \\ \Theta(t) \end{array}\right) + \left(\begin{array}{ccc} \sigma_{D,D} & \sigma_{D,\Pi} & 0 \\ 0 & \sigma_{\Pi,\Pi}& 0 \\ \sigma_{\Theta,D} & 0 & \sigma_{\Theta,\Theta} \end{array}\right) d \left(\begin{array}{c} w_{D}(t)\\ w_{\Pi}(t) \\ w_{\Theta}(t) \end{array}\right)$$


And here's the result I get (as you can see the equation gets out of the right page bound):

Note: I tried using

\resizebox{.9 \textwidth}{!}
{
$$[...] % My equation here$$
}


But I get a compilation error.

• Your attempt can be "rescued" by changing the nested equation enviroment to $\displaystyle ...$ and wrapping the equation environment around the resizebox. But really, using the matrix environments of amsmath and compressing the horizontal space is a much better approach. Commented Aug 10, 2020 at 17:09

As others have said it is best to avoid scaling. In this case you can most likely make it fit on one line without scaling. You are loading amsmath but not using its matrix environments which means that you have a lot more space around the large brackets than needed. That change and a small squeezing of the column spacing is all you need to make things fit here:

\documentclass[a4paper]{article}
\addtolength\textwidth{10mm}% try to get initial position like image shown No test file provided :(((
\usepackage{amsmath}

\begin{document}

original
$$d\left(\begin{array}{c} D(t) \\ \Pi(t) \\ \Theta(t) \end{array}\right) = \left(\begin{array}{ccc} -\alpha_{D} & 1 & 0 \\ 0 & -\alpha_{\Pi} & 0 \\ 0 & 0 & -\alpha_{\Theta} \end{array}\right) \left(\begin{array}{c} D(t) \\ \Pi(t) \\ \Theta(t) \end{array}\right) + \left(\begin{array}{ccc} \sigma_{D,D} & \sigma_{D,\Pi} & 0 \\ 0 & \sigma_{\Pi,\Pi}& 0 \\ \sigma_{\Theta,D} & 0 & \sigma_{\Theta,\Theta} \end{array}\right) d \left(\begin{array}{c} w_{D}(t)\\ w_{\Pi}(t) \\ w_{\Theta}(t) \end{array}\right)$$

ams matrices
$$\setlength\arraycolsep{4pt} d\begin{pmatrix} D(t) \\ \Pi(t) \\ \Theta(t) \end{pmatrix} = \begin{pmatrix} -\alpha_{D} & 1 & 0 \\ 0 & -\alpha_{\Pi} & 0 \\ 0 & 0 & -\alpha_{\Theta} \end{pmatrix} \begin{pmatrix} D(t) \\ \Pi(t) \\ \Theta(t) \end{pmatrix} + \begin{pmatrix} \sigma_{D,D} & \sigma_{D,\Pi} & 0 \\ 0 & \sigma_{\Pi,\Pi}& 0 \\ \sigma_{\Theta,D} & 0 & \sigma_{\Theta,\Theta} \end{pmatrix} d \begin{pmatrix} w_{D}(t)\\ w_{\Pi}(t) \\ w_{\Theta}(t) \end{pmatrix}$$
\end{document}

• Good catch, didn't try that one Commented Aug 10, 2020 at 15:52

The environment of choice for this case is multline.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{multline}
d\begin{pmatrix}
D(t) \\ \Pi(t) \\ \Theta(t)
\end{pmatrix}
=
\begin{pmatrix}
-\alpha_{D} & 1 & 0 \\
0 & -\alpha_{\Pi} & 0 \\
0 & 0 & -\alpha_{\Theta}
\end{pmatrix}
\begin{pmatrix}
D(t) \\ \Pi(t) \\ \Theta(t)
\end{pmatrix} \\
+
\begin{pmatrix}
\sigma_{D,D} & \sigma_{D,\Pi} & 0 \\
0 & \sigma_{\Pi,\Pi}& 0 \\
\sigma_{\Theta,D} & 0 & \sigma_{\Theta,\Theta}
\end{pmatrix}
d \begin{pmatrix}
w_{D}(t)\\ w_{\Pi}(t) \\ w_{\Theta}(t)
\end{pmatrix}
\end{multline}

\end{document}


Note the usage of pmatrix.

The objection that this doesn't directly answer the question should be rejected, but it's not difficult to make an example so you can judge for yourself.

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}

\newenvironment{scaledequation}
{$$\begin{lrbox}{\scaledequationbox}\displaystyle} {\end{lrbox}% \resizebox{0.9\displaywidth}{!}{\usebox{\scaledequationbox}}%$$
\ignorespacesafterend}
\newsavebox{\scaledequationbox}

\begin{document}

This is how a long equation should be treated when it's too wide for
fitting the given text width
\begin{multline}
d\begin{pmatrix}
D(t) \\ \Pi(t) \\ \Theta(t)
\end{pmatrix}
=
\begin{pmatrix}
-\alpha_{D} & 1 & 0 \\
0 & -\alpha_{\Pi} & 0 \\
0 & 0 & -\alpha_{\Theta}
\end{pmatrix}
\begin{pmatrix}
D(t) \\ \Pi(t) \\ \Theta(t)
\end{pmatrix} \\
+
\begin{pmatrix}
\sigma_{D,D} & \sigma_{D,\Pi} & 0 \\
0 & \sigma_{\Pi,\Pi}& 0 \\
\sigma_{\Theta,D} & 0 & \sigma_{\Theta,\Theta}
\end{pmatrix}
d \begin{pmatrix}
w_{D}(t)\\ w_{\Pi}(t) \\ w_{\Theta}(t)
\end{pmatrix}
\end{multline}
On the other hand, you could rescale the material to fit, with a
dubious result, which you can compare to the previous one
\begin{scaledequation}
d\begin{pmatrix}
D(t) \\ \Pi(t) \\ \Theta(t)
\end{pmatrix}
=
\begin{pmatrix}
-\alpha_{D} & 1 & 0 \\
0 & -\alpha_{\Pi} & 0 \\
0 & 0 & -\alpha_{\Theta}
\end{pmatrix}
\begin{pmatrix}
D(t) \\ \Pi(t) \\ \Theta(t)
\end{pmatrix}
+
\begin{pmatrix}
\sigma_{D,D} & \sigma_{D,\Pi} & 0 \\
0 & \sigma_{\Pi,\Pi}& 0 \\
\sigma_{\Theta,D} & 0 & \sigma_{\Theta,\Theta}
\end{pmatrix}
d \begin{pmatrix}
w_{D}(t)\\ w_{\Pi}(t) \\ w_{\Theta}(t)
\end{pmatrix}
\end{scaledequation}
I have no doubt whatsoever as to which one I'd choose.

\end{document}


• Hi, thanks for your answer! Very useful but it didn't directly answer to my question: do you know how to resize the equation? Commented Aug 10, 2020 at 15:27
• @Robb1 I added the requested code, even if it makes my eyes bleed. ;-) Commented Aug 10, 2020 at 15:41

It is never a good solution to start adjusting the font size of math, (1) it gives an inconsistent design, and (2) hurts readability. Instead learn to break mathematics it will become an important tool in your future documents.

\documentclass[a4paper]{article}
\usepackage{amsmath}
\begin{document}

\begin{aligned} d\begin{pmatrix}{c} D(t) \\ \Pi(t) \\ \Theta(t) \end{pmatrix} = {} & % note the {} in front of & in this case \begin{pmatrix} -\alpha_{D} & 1 & 0 \\ 0 & -\alpha_{\Pi} & 0 \\ 0 & 0 & -\alpha_{\Theta} \end{pmatrix} \begin{pmatrix} D(t) \\ \Pi(t) \\ \Theta(t) \end{pmatrix} \\ & + \begin{pmatrix} \sigma_{D,D} & \sigma_{D,\Pi} & 0 \\ 0 & \sigma_{\Pi,\Pi}& 0 \\ \sigma_{\Theta,D} & 0 & \sigma_{\Theta,\Theta} \end{pmatrix} d \begin{pmatrix} w_{D}(t)\\ w_{\Pi}(t) \\ w_{\Theta}(t) \end{pmatrix} \end{aligned}

\end{document}


here I've also used the pmatrix env as it gives less typing.

Note also how I provide a full minimal example including document class and appropriate preamble. This makes it a lot easier for others to test the code.

• Thanks for the suggestions, I learnt a lot from this answer! Still I would like to know how to scale an equation while using $$...$$, even if it's not recommended. Could you complete your answer adding this part? Commented Aug 10, 2020 at 15:24
• @Robb1 of course you can, but I'm not going to list it as it is not recommended and we generally don't want to waste time having to tell users to unlearn bad solutions they randomly found online. You can take a look at ams.org/arc/styleguide/mit-2.pdf chapter 3 especially 3.3.5, these are the guidelines that we normally use when we edit manuscripts. As you will notice, rescaling is never an option. Commented Aug 10, 2020 at 15:29
• thanks for the clarification but I still don't understand why wouldn't you answer my simple question. I am writing a simple pdf for myself, I am not going to publish this document and I find it more convenient for myself to have a slightly smaller equation. Where is the problem in that? Commented Aug 10, 2020 at 15:32
• @Robb1, if your life depends on resizing your formula which I would advise you against, you could load the following package \usepackage{adjustbox} and enclose your formula with \begin{adjustbox}{max width=.95\textwidth} and \end{adjustbox}` Commented Aug 10, 2020 at 15:32
• As I mention: others using the solution thinking it is a good idea to do so. As mentioned, you're better of learning to break math into lines Commented Aug 10, 2020 at 15:33