tags:

views:

86

answers:

2

Hi

I am using the exercise package to display exercises in a book. I have redefined some commands like this, which basically adds some space, a pencil, and two hrule's before and after the exercise:

\renewcommand{\ExerciseHeader}{\vskip 1em\hrule\vskip 1em\centerline{\textbf{\large\smallpencil
\ExerciseHeaderNB\ExerciseHeaderTitle%
\ExerciseHeaderDifficulty\ExerciseHeaderOrigin\medskip}}}
\makeatletter\def\endExerciseEnv{\termineliste{1}\@EndExeBox\vskip .5em\hrule\vskip 1em}\makeatother

Now this works, but there's a small problem:

There are situations where only the \hrule ends up being at the bottom of a page, and the rest of the exercise goes on the next page. There is also the opposite behavior: the entire exercise is on one page, except the \hrule in "endExerciseEnv", which is flushed to the next page.

My question is:

How to force the top hrule come

  • either together with the header of the exercise (caption, title, whatever not) and at least say 5em or so of "exercise text" (so it doesn't look ugly),
  • OR be flushed altogether, with the entire exercise?

Similar question for the bottom hrule: How to force it have at least 5 em of "exercise text" in front of it on the visible page where the hrule itself goes to? (or the beginning of the Exercise environment, whichever comes first - as it's the case if the environment is not higher than 5em)

Any LaTeX guru who knows that?

Addendum

I have asked in the past LaTeX questions like this and I've got answers which required me to do stuff manually, like "insert a \vskip here and there" or such. Let me be clear: This is a book, there's lot of exercises, and I NEED it be done "automatically", by going the proper way of redeclaring commands & co.

+2  A: 

TeX can insert page break before any glue, for example \vskip 1em.

Make some changes:

1) You write \vskip 1em\hrule\vskip 1em Replace it with

\vskip 1em\hrule \nobreak \vskip 1em

2) You write \vskip .5em\hrule\vskip 1em Replace it with

\nobreak\vskip .5em\hrule\vskip 1em

You also can insert \goodbreak to show good point to break the page. This good point can be inserted before and after your excersise.

1) \goodbreak\vskip 1em\hrule \nobreak \vskip 1em

2) \nobreak\vskip .5em\hrule \goodbreak \vskip 1em

Alexey Malistov
Thanks. I didn't try it out yet, but it looks good.
Flavius