# An environment to change the vertical space around a formula

Specially in beamer presentations, I use a custom environment to change the vertical space around a formula. The code is:

\newenvironment{shrinkeq}[1]
{ \bgroup
\addtolength\abovedisplayshortskip{#1}
\addtolength\abovedisplayskip{#1}
\addtolength\belowdisplayshortskip{#1}
\addtolength\belowdisplayskip{#1}}
{\egroup}


However, an unwanted horizontal space is added in front of the text following the formula. For example, the code

Text before text before text before\dots
$\int_{a_1}^{b_1}f(x)dx+\int_{a_2}^{b_2}g(x)dx+\int_{a_3}^{b_3}h(x)dx=0$
Text after text after text after\dots
\bigskip

Text before text before text before\dots
\begin{shrinkeq}{-2ex}
$\int_{a_1}^{b_1}f(x)dx+\int_{a_2}^{b_2}g(x)dx+\int_{a_3}^{b_3}h(x)dx=0$
\end{shrinkeq}
Text after text after text after\dots


produces

The issue can be fixed by putting a \null after \end{shrinkeq} but I do not understand why this works.

¿Is there a better way to do this?

-

## 1 Answer

Line breaks cause white space, like blanks do. Note the line break between \end{shrinkeq} and the following text.

A local solution would be commenting out the line break: \end{shrinkeq}%

A global solution would be adding \ignorespacesafterend to the end of your environment definition:

\newenvironment{shrinkeq}[1]
{ \bgroup
\addtolength\abovedisplayshortskip{#1}
\addtolength\abovedisplayskip{#1}
\addtolength\belowdisplayshortskip{#1}
\addtolength\belowdisplayskip{#1}}
{\egroup\ignorespacesafterend}


This definition causes that blanks and line breaks directly following the environment would be ignored.

-
Thank you Stefan! I did not know the <code>\ignorespacesafterend</code> command. –  rgallego Dec 9 '10 at 15:07