Automatically fit equation in align environment in page width

alignequations

I have an issue in a system I am working on where long equations go beyond the page width. The LaTeX is automatically generated by an algorithm and I would like to have a way to make it fit in the page even if that makes it a little smaller. This solution would be fine for cases where the equation is a little larger than the page width. Obviously for extreme cases the developer will have to split the equation into more equations.

In my estimate it is way harder to make the system automatically recognise positions in an equation where it could split it in more lines.

After going through various posts in this forum (for example this one can i use resize box in align) I have not found a working sample of code using \resizebox in an align environment. How could I resize the following equation for example to fit the page?

\begin{align*}
    N_{Ed0} &= N_x · \cos^2(\phi_0) + N_y · \sin^2(\phi_0) + 2 · N_{xy} · \sin(\phi_0) · \cos(\phi_0) - N_0 · \cot(\phi_0) \\
            &= (-1.81234E3) · \cos^2(47.0113) + (-9.06168E3) · \sin^2(47.0113) + 2 · 28.19E3 · \sin(47.0113) · \cos(47.0113) - 18.4356 · \cot(47.0113) = \mathbf{ 22.4121E3 \: N }
\end{align*}

PS: The decimal points are a user option so the solution could not be "reduce the decimals".

Best Answer

You need a horizontal mode construct in \resizebox I really can not recommend doing this at all as it quickly makes the math unreadable with no warning but:

enter image description here

\documentclass{article}

\usepackage{amsmath,graphicx}
\DeclareUnicodeCharacter{00B7}{\cdot}
\begin{document}
\noindent X\dotfill X
\begin{center}
\resizebox{\textwidth}{!}{$\begin{aligned}
    N_{Ed0} &= N_x · \cos^2(\phi_0) + N_y · \sin^2(\phi_0) + 2 · N_{xy} · \sin(\phi_0) · \cos(\phi_0) - N_0 · \cot(\phi_0) \\
            &= (-1.81234E3) · \cos^2(47.0113) + (-9.06168E3) · \sin^2(47.0113) + 2 · 28.19E3 · \sin(47.0113) · \cos(47.0113) - 18.4356 · \cot(47.0113) = \mathbf{ 22.4121E3 \: N }
\end{aligned}$}
\end{center}
\end{document}

I would drop the alignment and let latex break the inline math with no font scaling

enter image description here

\usepackage{amsmath,graphicx}
\DeclareUnicodeCharacter{00B7}{\cdot}
\begin{document}
\noindent X\dotfill X
\begin{center}
$
    N_{Ed0} = N_x · \cos^2(\phi_0) + N_y · \sin^2(\phi_0) + 2 · N_{xy} · \sin(\phi_0) · \cos(\phi_0) - N_0 · \cot(\phi_0) $\\$
            = (-1.81234E3) · \cos^2(47.0113) + (-9.06168E3) · \sin^2(47.0113) + 2 · 28.19E3 · \sin(47.0113) · \cos(47.0113) - 18.4356 · \cot(47.0113) = \mathbf{ 22.4121E3 \: N }
$
\end{center}
\end{document}
Related Question