[Tex/LaTex] How to resize font of displayed formulas to automatically fit column width?

fontsizemath-mode

Is there a way, in LaTeX, to automatically resize font of displayed equations to fit column width (241 pt, here)?

Any ideas would be appreciated.

You can see my equation below; note that I use \fontsize{4pt}{4pt}\selectfont to resize the font, but I need the font to be resized automatically every time.

{\fontsize{4pt}{4pt}\selectfont{\begin{gather}\begin{gathered}{\varphi 
}_{ij}^{q}\left(t\right)=2\left[\dfrac{{S}_{a}}{{L}_{a}^{2}}{e}^{-({\Vert 
{x}_{j}(t)-{x}_{i}(t)-{\Delta }_{ij}^{q}\Vert 
}^{2}/{L}_{a}^{2})}-\dfrac{{S}_{r}}{{L}_{r}^{2}}{e}^{-({\Vert 
{x}_{j}(t)-{x}_{i}(t)-{\Delta }_{ij}^{q}\Vert 
}^{2}/{L}_{r}^{2})}+\left(\dfrac{{S}_{r}}{{L}_{r}^{2}}+\dfrac{{S}_{r}}{{L}_{a}^{2}}\right){e}^{(-1/{L}_{r}^{2}+1/{L}_{a}^{2})({\Vert 
{x}_{j}(t)-{x}_{i}(t)-{\Delta }_{ij}^{q}\Vert 
}^{2})}\right].\label{eq6}\end{gathered}\end{gather}}}

Best Answer

The adjustbox package is handy. You put the contents inside adjustbox environment as

\begin{adjustbox}{max width=241pt}
contents
\end{adjustbox}

then if the contents are wider than 241pt, then only they are resized otherwise not.

\documentclass{article}
\usepackage{amsmath}
\usepackage{adjustbox}

\begin{document}
\noindent A\hfill Z
\begin{equation}
\begin{adjustbox}{max width=241pt}
$
  \varphi_{ij}^q(t) =
  2\left[
    \dfrac{S_a}{L_a^2}
    e^{ -(\Vert x_j(t) - x_i(t) - \Delta_{ij}^q\Vert^2/L_a^2)}
    - \dfrac{S_r}{L_r^2}
    e^{ -(\Vert x_j(t) - x_i(t) - \Delta_{ij}^q\Vert^2/L_r^2)}
    + \left( \dfrac{S_r}{L_r^2} + \dfrac{S_r}{L_a^2} \right)
    e^{(- 1/L_r^2 + 1/L_a^2)
       (\Vert x_j(t) - x_i(t) - \Delta_{ij}^q\Vert^2)}
  \right]
  \label{eq6}
$
\end{adjustbox}
\end{equation}
\end{document}

enter image description here