12

This recent question on how to increase the width of the output, and this earlier question on how to increase the length of the output reminded me of something I have been wondering: I would like to fix the width and have the length to be longer than some minimum length, but only as long as necessary.

So far I have been using the geometry package to fix the width, and set the page length to be very long as per the above links, and this has been working. However, I would like to not have the extra blank space at the bottom for very short pages.

This is intended to generate individual pages for on screen viewing, and not a long document. Hence the desire for a single "page".

Peter Grill
  • 223,288

1 Answers1

12
\documentclass{article}
\usepackage{geometry}
\geometry{paperwidth=12cm,paperheight=\maxdimen,margin=1cm}

\usepackage{lipsum}

\begin{document}
\setbox0=\vbox{
\lipsum
}
\dimen0=\dp0
\pdfpageheight=\dimexpr\ht0+2cm\relax
\ifdim\pdfpageheight<12cm \pdfpageheight=12cm \fi
\unvbox0\kern-\dimen0

\end{document}

If you try \lipsum[1] instead of \lipsum you get 12cm as height. This can be made automatic, I believe, by hooking into \begin{document} and \end{document}.

egreg
  • 1,121,712
  • This seems to do exactly what I need. I'll see if I can figure out how to wrap it around \begin{document} and end{document}. Thanks. – Peter Grill Jun 02 '11 at 18:19
  • I am accepting this as it does what I want. I have not been able to automate this yet, but will keep trying to figure that out as it should not be that hard. – Peter Grill Jun 20 '11 at 17:40
  • 2
    The automation is described here: http://tex.stackexchange.com/a/27057/7323 – Patrick Häcker Apr 14 '14 at 14:27