[OS X TeX] environment question
Alan Munn
amunn at msu.edu
Tue May 19 14:50:24 EDT 2009
At 12:03 PM -0400 5/19/09, Art Werschulz wrote:
>Hi.
>
>I have created an environment called "offset", which I use for
>material that needs to be offset from the main text flow. Here is a
>small LaTeX file that illustrates its definition and use.
>
><snip>
>\documentclass{article}
>
>\newenvironment{offset}[1]%
> {\bigskip\hrule\nopagebreak[4]\bigskip\nopagebreak[4]\noindent%
> \textbf{#1}\nopagebreak\par\medskip\nopagebreak\noindent}%
> {\nopagebreak[4]\bigskip\hrule\bigskip}
>
>\begin{document}
>My first example is
>\begin{offset}{Addition rule (elementary version)}%
> Given two disjoint events, $E_1$ and $E_2$, with associated
> probabilities P($E_1$) and P($E_2$), the probability of $E_1$
> \emph{or} $E_2$ occurring is equal to
> to $P(E_1) + P(E_2)$. That is,
> \[P(E_1 \cup E_2) = P(E_1) + P(E_2)\]
> if $E_1$ and $E_2$ are disjoint.
>\end{offset}
>As you can see, this looks pretty good.
>
>My second example is:
>\begin{offset}{Addition rule (general version)}%
> Given events $E_1$ and $E_2$, with associated
> probabilities $P(E_1)$ and $P(E_2)$, the probability of $E_1$
> \emph{or} $E_2$ occurring is
> \[P(E_1\cup E_2) = P(E_1) + P(E_2) - P(E_1 \cap E_2)\]
>\end{offset}
>That extra space between the math display and the horizontal line is
>ugly.
>
>\end{document}
></snip>
>
>Note the following:
>(1) The comment about the extra (vertical) space.
>(2) I need to put a % after the argument, to avoid an extra horizontal space.
>Any ideas how to fix this? Is there something pre-existing that I
>can use instead?
For (2) do the following:
\newenvironment{offset}[1]%
{\bigskip\hrule\nopagebreak[4]\bigskip\nopagebreak[4]\noindent%
\textbf{#1}\nopagebreak\par\medskip\nopagebreak\noindent\ignorespaces}%
{\nopagebreak[4]\bigskip\hrule\bigskip}
For (1) you could put
\belowdisplayshortskip{1ex plus .5ex minus .5ex}
at the beginning of the environment, but this will also affect
displayed math other places within the environment. (And this still
might look like too much space)
If this is not a very common occurrence you could not change the
\belowdisplayshortskip and just put
\vspace{-3.5ex} after and displayed equation that is last in the environment:
\begin{offset}{Addition rule (general version)}
Given events $E_1$ and $E_2$, with associated
probabilities $P(E_1)$ and $P(E_2)$, the probability of $E_1$
\emph{or} $E_2$ occurring is
\[P(E_1\cup E_2) = P(E_1) + P(E_2) - P(E_1 \cap E_2)\]
\vspace{-3.5ex}
\end{offset}
Ideally if there was a way to check whether the last element in the
environment was the end of a display or not you could put the \vspace
command within a conditional in the environment itself, but I don't
think there is any way to check that sort of thing.
Alan
--
Alan Munn amunn at msu.edu
Department of Linguistics
and Germanic, Slavic, Asian and African Languages Tel.
517-355-7491
Michigan State University, East Lansing MI 48824 USA Fax 517-432-2736
More information about the MacOSX-TeX
mailing list