Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm working on a homework set, and one of my answers to a multi-part question has become very long. I've been keen on keeping problems and solutions as much on the same page as possible, and my current solution (of putting both the question and its solution in a minipage) turns out to be rather less than optimal, as it forces everything too strictly to be on the same page, and moves a question to its own page even when it's not strictly necessary.

What I'd like is something like the following:

1. Question
  a) Subquestion #1
     Solution
---page break here if necessary---
  b) Subquestion #2
     Solution
---page break here if necessary---
2. Question
...

I've been doing minipage around the whole question/subquestion/solution block, but this obviously forces everything onto the same page. I've played around with samepage and nobreak and nopagebreak and even putting each individual block described above in its own minipage, which seems to really mess up enumeration and all sorts of spacing. nopagebreak seems to not want to work at all for some reason for me.

What's a good way to a do this? Thanks in advance, and please let me know if I've been vague at all.

share|improve this question
1  
Welcome to TeX.SE. It is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages. In this case it would go a long way toward explaining the enumeration problems you mention as I was about to recommend that you put each subsection in a minipage. –  Peter Grill Sep 10 '12 at 1:11
    
Thanks so much, @PeterGrill! I'll update right now. –  David Millard Sep 10 '12 at 3:43
    
Actually, it turns out my use of a description list instead of a more appropriate class was ruining horizontal alignment. Sorry, and thanks for your help. –  David Millard Sep 10 '12 at 3:57
2  
As it seems you found a way to solve your problem, it would be really nice if you could share that solution with us, so that others who come across the same problem may find help more easily. Answering your own question is desired on this site! –  canaaerus Sep 10 '12 at 6:21

1 Answer 1

up vote 5 down vote accepted

From your problem description I assume that

  • what you are interested in is breaking more or less only after solutions
  • you will accept varying white space at the bottom of the pages

In that case my suggestion would be to use \filbreak which is a plain TeX command that is also available in LaTeX. Its definition is (roughly)

\newcommand\filbreak{\vfil\penalty-200\vfilneg}

This means: fill the remainder of the page with whitespace and consider this solution a "page good break point" (negative penalty). But then back up to the current point and continue typesetting. So this will be taken unless a better break comes along later. Because of the negative penalty (in addition to the resulting page having optional badness) not many natural breakpoints can compete.

Placing such a command in every place that are good candidate for pagebreaks will give you the desired result and it could even easily added to some environments that suround your questions and answers.

There is however one exeption: if one question+solution is actually more than a page then it doesn't really make sense to start it on a new page and leave the previous half empty. But the above solution would do this, because it sees the first \filbreak and then nothing that is a better pagebreak and therefore eventually backs up to this breakpoint. If that happens then the answer is to manually correct that page by taking out the previous \filbreak or by adding one explicit page break in addition.

share|improve this answer
    
This is fantastic! Thanks so much, I'd never even heard of \filbreak. –  David Millard Sep 20 '12 at 1:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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