# Is there any macro to automatically scale the math equations to adapt the line width?

Sometimes I have huge math equations which are longer than the linewidth, so I am wondering if here is some macro to zoom in the equation to avoid it being rendered outside the line? (I am using \twocolumn style). The overlong equations are damn ugly.

Like the code

\documentclass{article}
\begin{document}
\twocolumn
\setlength{\columnseprule}{0.4pt}
$\frac{veryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongword}{a}$
\newpage
$\frac{veryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongword}{a}$
\end{document}


The two long fraction will overlap each other. I want to have the overlong equations to zoom in to adapt the linewidth.

• Try with \usepackage{graphicx} and then $\resizebox{.9\columnwidth}{!}{\displaystyle \frac{<num>}{<denom>}}$. It will still look ugly though. It may be better to restructure your \frac by using other symbols instead, and define the symbols to mean more complex things within the text (say).
– Werner
Mar 8, 2017 at 3:46

If the main issue is with very long numerator (or denominator) terms in a \frac expression, try using the \splitfrac macro that's provided by the mathtools package. Note: \splitfrac directives may be nested, if needed.

This method doesn't provide automatic line breaks, as you seem to want to have. But then only the writer -- certainly not the software -- is in a position to judge where having line breaks would be OK. And, for sure, splitting a long numerator deliberately produces far better typographic results than does shoehorning the entire equation into the with of the column via a \resizebox directive -- see below.

\documentclass[twocolumn]{article}
\setlength{\columnseprule}{0.4pt}
\usepackage{graphicx}  % for "\resizebox" macro
\usepackage{mathtools} % for "\splitfrac" macro
\begin{document}
$\frac{\splitfrac{veryveryveryveryveryveryveryvery}{veryveryveryveryveryveryverylongword}}{a}$
vs.
$\resizebox{0.95\columnwidth}{!}{\displaystyle \frac{veryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongword}{a}}$
\end{document}

• Thank you. resizebox fits me better. But here's another problem that 'resizebox' will enlarge the short equations. Is here any way to take the overlong equations out? (or the inline equations that extrude the boundary) Mar 8, 2017 at 10:13
• @SuiChen you can specify max width with resizebox but look at the adjustbox package which has a nicer interface for such things Mar 8, 2017 at 13:15
• @SuiChen - Just to follow up on David's comment: To implement his suggestion, you'd load the adjustbox package in the preamble and type something like $\adjustbox{max width=0.95\columnwidth}{\displaystyle\frac{<numerator>}{<denominator>}}$ in the body of the document.
– Mico
Mar 8, 2017 at 15:28