3

So I've got a document that is leading off with a minipage. From what I understand, the minipage environment tries to fit the box it creates on the current page, and if it is unable to do so, it moves itself to the top of the next page. The document that I have is currently doing that, because the minipage is slightly larger than the page itself. As such, it moves itself to the next page, despite there being nothing before it on the page. Is there a way to get it to not flee away like this?

Here is a MWE

\documentclass{article}
\usepackage[a4paper, portrait, margin=0.75in]{geometry}
\pagenumbering{gobble}
\usepackage{lipsum}
\begin{document}
\begin{minipage}{5 in}
\lipsum[10-25]
\end{minipage}
\end{document}

Using this generates a two page pdf. The first is blank, the second contains the lorem ipsum text flowing longer than the page itself. If you change the amount of text used so that it fits on one page, then it magically doesn't create the blank page either.

  • your description of minipage is rather misleading. minipage has no positioning logic at all, it just makes a box the size of its contents, that box is then positioned the same way as a big letter, it may be on the same line or same page as preceding text according to the normal line and page breaking that tex does, the line and page breaker has no information that it was a minipage – David Carlisle Oct 24 '17 at 9:35
  • @DavidCarlisle I guess. I think my question is that, when LaTeX senses a box larger than what can fit on the page, it moves it to the next page and puts it at the top of that page. Why is it not just staying on the first page, given that there is nothing else on the page? – Leo Bloom Oct 25 '17 at 1:01
  • it's just a more or less accidental fallout from an error condition, basically by the time it knows the box is overfull it doesn't know that there is nothing else on the page (it doesn't know there is a single box bigger than the page, it only knows the total page content is too big) and anyway it doesn't do anything about it. Essentially it's a user error (although only reported as a warning) and in all cases after a user error the log file is far more important than the typeset output. The intention is that the source is fixed, not that the output is great. – David Carlisle Oct 25 '17 at 7:15
2

Based on the fact that you want to force the content to remain on the current page, yet it is just too tall to fit, you can \smash it (removing any vertical height) and then force a jump to the following page (if needed for additional content):

\documentclass{article}

\usepackage[a4paper, portrait, margin = 0.75in]{geometry}
\usepackage{lipsum}

\pagenumbering{gobble}

\begin{document}

\smash{% Your over-sized minipage...
  \begin{minipage}[t]{5in}
    \lipsum[10-25]
  \end{minipage}%
}

\clearpage

abc % Page 2 content

\end{document}
  • This works fine for this toy example, but rarely in practice because a minipage that occupies the whole of a page will frequently have several paragraphs. Try replacing \lipsum[10-25] with \lipsum[10-24]\par\lipsum[25] (or with a blank line in place of \par). You'll be told "Paragraph ended before \makesm@sh was complete." The problem is that plain TeX does not define \makesm@sh (the main implementation of \smash) using \long\def. – richard Jun 17 at 10:25
1

You need to use \smash to tell LaTeX to ignore the height of the box, and then \clearpage to manually insert a page break, as per Werner's answer. However most of the time you cannot simply wrap a \smash around the minipage environment, because it will typically contain paragraph breaks and \smash does not allow these in its argument. The solution is to use the lrbox environment to save the page into a box and then \smash that. We can package this up into a new environment, which I've called smashminipage.

\documentclass{article}
\usepackage{lipsum}

\newsavebox\thesmashminipage
\newenvironment{smashminipage}
  {\begin{lrbox}{\thesmashminipage}\begin{minipage}[t]{\textwidth}}
  {\end{minipage}\end{lrbox}\smash{\usebox{\thesmashminipage}}\clearpage}

\begin{document}
\begin{smashminipage}
\lipsum[10-17]

\lipsum[18-25]
\end{smashminipage}

Page 2 content
\end{document}

For a slightly more robust version of this smashminipage environment that will work if your page with a multicols, tikzpicture or title in a much larger font, you'll need to add a \null at the start of the minipage, e.g.

\newenvironment{smashminipage}
  {\begin{lrbox}{\thesmashminipage}\begin{minipage}[t]{\textwidth}
   \null\par\vspace{-\baselineskip}}
  {\end{minipage}\end{lrbox}\smash{\usebox{\thesmashminipage}}\clearpage}

I admit I don't really understand why this is needed, which is why I haven't added that to my initial answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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