6

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.

  • 4
    Please, don't inflict this to your readers. – egreg Jan 12 '16 at 11:29
  • @egreg I wouldn't do it, but I am trying to help a colleague who does not wish to break his equation across lines. I suppose the "help" you would recommend would be to tell him to not do it this way. – Steven B. Segletes Jan 12 '16 at 11:31
6

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

  • seems to me that this might allow the equation to go right off the paper. wouldn't a warning be friendly in case the thing gets too wide? – barbara beeton Jan 12 '16 at 17:10
  • 1
    @barbarabeeton My idea would be to add an error message: “Wrong typesetting requested” ;-) – egreg Jan 12 '16 at 17:22
  • @egreg Can this work for other math environments like align? – Mathemanic Mar 29 '16 at 19:23
2

Here is a solution with the eqparbox package, which allows measurement of tagged boxes. It requires two compilations:

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{mathtools}
\usepackage{eqparbox}

\begin{document}

\lipsum[1]
\noindent\makebox[\textwidth]{\begin{minipage}{\dimexpr\eqboxwidth{Eq}+1Acm\relax}
  \medskip
  \begin{equation}\eqmakebox[Eq]{\ensuremath{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{\belowdisplayskip}
\lipsum[2]
\begin{equation}
  \nu = c / \lambda
\end{equation}

\end{document} 

enter image description here

2

It seems that you could also use the adjustwidth environment from the changepage package:

\newenvironment{widerequation}{%
    \begin{adjustwidth}{-2cm}{-2cm}\begin{equation}}
    {\end{equation}\end{adjustwidth}}

Here's a complete MWE:

% arara: pdflatex
\documentclass{article}
\usepackage{amsmath}
\usepackage{changepage}
\usepackage[nopar]{lipsum}

\newenvironment{widerequation}{%
    \begin{adjustwidth}{-2cm}{-2cm}\begin{equation}}
    {\end{equation}\end{adjustwidth}}

\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}
  • This is a real nice answer, if the adjustment is always to be of fixed width. Thanks! – Steven B. Segletes Jan 12 '16 at 16:53
  • 1
    @cmhughes Can this work for other math environments like align? – Mathemanic Mar 29 '16 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.