# Centering an equation that's wider than \textwidth?

What to do if one want's to center an equation that's to wide for the margins and the equation isn't possible to split between rows like my example where there is a big fraction containing Mclaurinexpansions.

I'm searching for solutions that either just center the equation on the a4 paper or that can scale down the size of the equation so it fits.

Thanks in advance for shared knowledge!

• \usepackage{mathtools} then put a \mathclap around the complete equation, like so: $$\mathclap{my really long formula}$$. – Skillmon likes topanswers.xyz Nov 28 '18 at 14:29
• Can't you factor out the denominator, put a big parenthesis and split the numerator on multiple lines? Personally, I'd prefer to see this than an equation that goes over into the margin, or a reduced fontsize. – G. Gare Nov 28 '18 at 14:30
• Just realizing that \mathclap might put the equation number over the equation. – Skillmon likes topanswers.xyz Nov 28 '18 at 14:31
• off topic: don't forget to use \cdots after the minus sign. – Sigur Nov 28 '18 at 14:31
• hm could test the \mathclap, worst case I will skipp the equation number and add it manually with hyper ref in the text above. – Victor Ekekrantz Nov 28 '18 at 14:35

\noindent
\makebox[\textwidth]{\parbox{1.3\textwidth}{%
\begin{align}
y &= f(x)\\
khdakshdkashdkajhsdkjahsdkh &= ksdjhf lksjdh fkjsdh fökjH SDÖKJFH ÖDFH öDFH
KSHDFKS
\end{align}
}}


However, it makes more sense to split the formular in pieces.

I propose three other possible layouts, with mathtools and/or nccmath:

 \documentclass{article}
\usepackage{mathtools, nccmath}
\usepackage{lipsum}

\begin{document}
\lipsum[11]
\begin{fleqn}[-0.75em]
\begin{aligned}[b] &\hspace{0.67em} f(x) = \\ & \frac{\Bigl(6x-x^2 + \cfrac{x^5}{20}-\dotsm\Bigr) +\Bigl(x^3-\cfrac{x^6}{2} + \cfrac{x^9}{3}-\dotsm\Bigr) + \Bigl(x^3-\cfrac{x^6}{2} + \cfrac{x^9}{3}-\dotsm\Bigr)-6x}% {\Bigl(x^3-\cfrac{2x^5}{3} + \cfrac{23x^7}{45}-\dotsm\Bigr)-x^3} \end{aligned}
\end{fleqn}
\bigskip

$$f(x) = \mfrac{\Bigl(6x-x^2 + \cfrac{x^5}{20}-\dotsm\Bigr) +\Bigl(x^3-\cfrac{x^6}{2} + \cfrac{x^9}{3}-\dotsm\Bigr) + \Bigl(x^3-\cfrac{x^6}{2} + \cfrac{x^9}{3}-\dotsm\Bigr)-6x}% {\Bigl(x^3-\cfrac{2x^5}{3} + \cfrac{23x^7}{45}-\dotsm\Bigr)-x^3}$$
\bigskip

$$f(x) = \frac{\splitfrac{\Bigl(6x-x^2 + \cfrac{x^5}{20}-\dotsm\Bigr) +\Bigl(x^3-\cfrac{x^6}{2} + \cfrac{x^9}{3}-\dotsm\Bigr)} {+ \Bigl(x^3-\cfrac{x^6}{2} + \cfrac{x^9}{3}-\dotsm\Bigr)-6x}}% {\Bigl(x^3-\cfrac{2x^5}{3} + \cfrac{23x^7}{45}-\dotsm\Bigr)-x^3}$$

\end{document}


Here is an another way to centre an equation that is too wide to fit within the text area. It is similar to the solution proposed by Skillmon in this comment, but it wraps your equation in a box whose width is exactly the maximal of the equation instead of one of width zero. This causes the equation number to be pushed to the next line, as desired.

\documentclass{article}

\usepackage{showframe} %% <- Makes the text margins visible
\usepackage{amsmath}

\begin{document}

$$\makebox[\displaywidth]{\displaystyle f(x) = \frac{ \Bigl( 6x - x^2 + \dfrac{x^5}{20} - \dotsb \Bigr) + \Bigl( x^3 - \dfrac{x^6}{2} + \dfrac{x^9}{3} - \dotsb \Bigr) + \Bigl( x^3 - \dfrac{x^6}{2} + \dfrac{x^9}{3} - \dotsb \Bigr) - 6x }{ \Bigl( x^3 - \dfrac{2x^5}{3} + \dfrac{23x^7}{45} - \dotsb \Bigr) - x^3 } }$$

\end{document}


The code is probably mostly self-explanatory, but here is a short explanation anyway:

• \makebox[<width>]{<content>} creates a box of width <width> that contains <content> (centred).
• \displaywidth is the maximum width of the current display math environment.
• $\displaystyle <equation>$ produces an equation set in display style (with large fractions, summation symbols etc.).

## Alternative: reduce the amount of empty space in the equation

As an alternative to allowing your equations to stick out of the margins, I suggest reducing the amount of space between its constituents. This can be done as follows:

\documentclass{article}
\usepackage{showframe} %% <- Makes the text margins visible
\usepackage{amsmath}

\newcommand*\squeezespaces[1]{% %% <- #1 is a number between 0 and 1
\thickmuskip=\scalemuskip{\thickmuskip}{#1}% %% <- around =, \rightarrow, etc.
\medmuskip=\scalemuskip{\medmuskip}{#1}%     %% <- around +, \times, etc.
\thinmuskip=\scalemuskip{\thinmuskip}{#1}%   %% <- around \sum, \sin, etc.
\nulldelimiterspace=#1\nulldelimiterspace    %% <- around fractions
\scriptspace=#1\scriptspace                  %% <- after sub-/superscripts
}
\newcommand*\scalemuskip[2]{% %% <- scales muskips, including stretch/shrink
\muexpr #1*\numexpr\dimexpr#2pt\relax\relax/65536\relax
} %% <- based on  https://tex.stackexchange.com/a/198966/156366

\begin{document}

$$\squeezespaces{.6} f(x) = \frac{ \Bigl( 6x - x^2 + \dfrac{x^5}{20} - \dotsb \Bigr) + \Bigl( x^3 - \dfrac{x^6}{2} + \dfrac{x^9}{3} - \dotsb \Bigr) + \Bigl( x^3 - \dfrac{x^6}{2} + \dfrac{x^9}{3} - \dotsb \Bigr) - 6x }{ \Bigl( x^3 - \dfrac{2x^5}{3} + \dfrac{23x^7}{45} - \dotsb \Bigr) - x^3 }$$

\end{document}


The three lengths \thickmuskip, \medmuskip and \thinmuskip determine the amount of space that is inserted between various types of math atoms (see this answer for a nice overview of when each is used). \nulldelimiterspace and \scriptspace are inserted around fractions and after sub-/superscripts respectively. I'm reducing each of them to 60% of their original values (within this equation only).

If you want the equation number to appear on the same line you can of course compress the equation even further. The following image was produced by replacing .6 by .45 in the previous document.