[Tex/LaTex] Temporarily Change Equation Margin

equationsmargins

Let's say I have a document with a narrow text width and lots of margin to spare. If I had a particularly long equation that failed to fit into the given width, the general solution would be to break the equation across multiple lines.

But if a particular equation was not well suited to that approach, is there a convenient way to temporarily change the margins just for a given equation? I provide a kludged approach below, but it requires manually inserted \vspace of an empirically derived magnitude. It just seems that there should be a better way. It also requires a specification of the widened textwidth, but that is OK, since I would prefer some uniformity of expansion, if the technique has to be used more than once in a document.

\documentclass{article}
\usepackage[nopar]{lipsum}
\begin{document}
\lipsum[1]
\begin{equation}
y = mx + b
\end{equation}
\lipsum[2]
% HERE IS THE KLUDGE
  \par\vspace{-.5\topskip}\noindent\makebox[\textwidth]{\begin{minipage}{7in}
    \begin{equation}
      E = mc^2 + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + 
      x + x + x + x + x + x + x + x + x 
    \end{equation}
  \end{minipage}}\vspace{\topskip}\par
% END KLUDGE
\lipsum[2]
\begin{equation}
\nu = c / \lambda
\end{equation}
\end{document}

enter image description here

As an afterthought, I would note that \leftskip and \rightskip approaches do not seem to change what happens inside the equation.

Best Answer

I'd avoid doing this as hard as I can. But…

\documentclass{article}
\usepackage{amsmath,environ}

\usepackage[nopar]{lipsum}

\makeatletter
\NewEnviron{widerequation}{%
  \begin{equation*}
  \sbox\z@{\let\label\@gobble$\displaystyle\BODY$}
  \makebox[\textwidth]{%
    \begin{minipage}{\dimexpr\wd\z@+3em}
    \vspace{-\baselineskip}
    \begin{equation}
    \BODY
    \end{equation}
    \end{minipage}%
  }
  \end{equation*}
}

\begin{document}
\lipsum[2]
\begin{equation}
y = mx + b
\end{equation}
\lipsum[2]
\begin{widerequation}\label{test}
      E = mc^2 + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + 
      x + x + x + x + x + x + x + x + x 
\end{widerequation}
\lipsum[2]
\begin{equation}
\nu = c / \lambda
\end{equation}
See \eqref{test}
\end{document}

enter image description here

Related Question