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 looking for a way to span minipages across pages in LaTeX.

I have a collection of recipes (presented through the recipe environment provided by the cuisine package) that varies in length, from something like 10 lines to more than can fit on a page. I want to fit as many as possible on one page and span the text across pages only if necessary. Until now I used the minipage environment that is sufficient if the content is not longer than a page.

Is there a way to get a "2 pages"-minipage or something similar ?

EDIT:

I have something like : texts A, B, C and D. I don't want them to span across pages if not necessary.

  • AAAABB (newpage) BBCCDD is not acceptable
  • AAAA (newpage) BBBB (newpage) CCDD is the desirable output

EDIT:

My content is a collection of recipes from the cuisine package.

share|improve this question
2  
I am not quite sure I understand the question. What is the reason to use a minipage in the first place? What is it about minipage environment that you need? Are you putting the texts in several columns? Would something like the flowfram package (ctan.org/tex-archive/macros/latex/contrib/flowfram) help? –  Jan Hlavacek Sep 17 '10 at 18:21
1  
I'm using the minipage environment because it guarantees that the text contained doesn't span pages. But it is too strict for me ... –  Thomas Schwery Sep 19 '10 at 9:35
    
Example: assuming "A" means typeset text from recipe (a) of height 1/6th available height, AAAA BBBBCC DD looks like it fits your constraint. Is it acceptable? –  Charles Stewart Sep 20 '10 at 9:24

3 Answers 3

up vote 6 down vote accepted

Your specification is too vague. You want to fit as many onto one page as possible, but some are larger than a single page so they should be split. What's the criterion for allowing a split? I'd do something like this:

  1. Typeset the recipe in a box and measure it.

  2. If it's shorter than some constant length (say 40% the height of the page), then put it in a minipage on the page.

  3. If it's longer, insert it onto the page without using minipage (hence allowing it to split)

Here's code to do something like this:

\documentclass{article}
\usepackage{lipsum,environ}
\newsavebox\recipebox
\newlength\recipebreaklength
\setlength\recipebreaklength{0.4\textheight}
\newcommand\typesetrecipe[1]{%
  \par\noindent\rule{\linewidth}{1ex}\par
  \BODY
  \par\noindent\rule{\linewidth}{1ex}\par
}
\NewEnviron{recipe}{%
  \savebox{\recipebox}{\parbox{\linewidth}{%
    \typesetrecipe{\BODY}%
  }}%
  \ifdim
      \dimexpr\ht\recipebox+\dp\recipebox\relax 
      > \recipebreaklength
    \typesetrecipe{\BODY}%
  \else
    \par\noindent\usebox\recipebox
  \fi
  \bigskip
}
\begin{document}
\raggedbottom
\begin{recipe}\lipsum[2]\end{recipe}
\begin{recipe}\lipsum[3]\end{recipe}
\begin{recipe}\lipsum[4]\end{recipe}
\begin{recipe}\lipsum[5]\end{recipe}
\begin{recipe}\lipsum[6]\end{recipe}
\begin{recipe}\lipsum[7-10]\end{recipe}
\end{document}
share|improve this answer
    
Can't the second occurence of \typesetrecipe{\BODY} just be \unvbox\recipebox? Then \BODY only gets evaluated once. –  Charles Stewart Sep 20 '10 at 9:30
2  
Not the way that I coded it, unfortunately (coz there's another box inside). I always try to use LaTeX idioms for such demonstration code, and to use \unvbox I'd need to start from scratch with \setbox\recipebox=\vbox{\hsize=\linewidth...} kind of thing. But that would be the better way to do it, I agree. –  Will Robertson Sep 20 '10 at 9:47

You can put the text into a \vbox and test if it is too long to fit the page. If not, you can set it, otherwise you can \vsplit it across two pages.

I asked a somewhat similar question on SO, Making Latex typeset given text on two facing pages; Steve's answer can be tailored for your requirements.

share|improve this answer

Use the samepage environment for the stuff you want to stay on the same page. You'll likely need \raggedbottom as well.

share|improve this answer
    
I'm using another environment to present my text (recipe) and it doesn't seem to "like" the samepage. The "recipes" are divided between pages. –  Thomas Schwery Sep 19 '10 at 16:08
    
That's not really enough information to go on. Can you provide a minimum example that fails with samepage? –  TH. Sep 19 '10 at 21:09

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.