Christian
Christian

Reputation: 2282

Force a maximum number of pages in LaTeX

Is there a way to give LaTeX a hint on the maximum number of pages I would like the document to have, so LaTeX at least tries to not exceed this maximum if possible?

Upvotes: 16

Views: 23564

Answers (3)

Rob Hyndman
Rob Hyndman

Reputation: 31810

No. LaTeX optimizes text at page level but not document level. So there is no way to automatically squeeze the text into a maximum number of pages. However, there are lots of ways to squeeze things in order to reduce the number of pages. See this blog post on "Squeezing space with LaTeX".

Upvotes: 8

Compholio
Compholio

Reputation: 1001

While you can't make a "suggested" page length, you can enforce a page limit where any pages past the limit will not print. Here's an example of a command you can create in your preamble to do this:

\makeatletter
\newcounter{pagecount}
\newcommand{\limitpages}[1]{
    \setcounter{pagecount}{0}%
    \gdef\maxpages{#1}%
    \ifx\latex@outputpage\@undefined\relax%
        \global\let\latex@outputpage\@outputpage%
    \fi%
    \gdef\@outputpage{%
        \addtocounter{pagecount}{1}%
        \ifnum\value{pagecount}>\maxpages\relax%
            % Do not output the page
        \else%
            \latex@outputpage%
        \fi%
    }%
}
\makeatother

Upvotes: 7

yCalleecharan
yCalleecharan

Reputation: 4704

It's good to look at the suggested answer but you should ask yourself why you would like to force LaTeX to restrict the number of pages. With LaTeX you should be focusing on the content and leave most of the formatting for the TeX system. If you're writing too much then learn how to reformulate your words more concisely. Trying to have abnormal settings in LaTeX internal variables may in the end lead to a document that's not aesthetically pleasing.

Upvotes: 0

Related Questions