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".

8
  • @Peter: \newgeometry and \restoregeometry from geometry could be what you are looking for?
    – egreg
    Commented Jun 2, 2011 at 9:25
  • But how do I determine how long to set the page? The page length is not fixed. If I add more text I want the page length to grow, and if I delete text I want the page length to shrink (but not shrink below a certain minimum) Commented Jun 2, 2011 at 9:46
  • @Peter paperheight=200cm?
    – egreg
    Commented Jun 2, 2011 at 9:54
  • 1
    See my answer to Automatically increase PDF page height for a solution based on preview. The minimal length would need to be implemented in addition. Commented Jun 2, 2011 at 11:12
  • @egreg: I don't know upfront how long the page is going to be. So I need to wrap the \begin{document} and \end{document} in a \newcommand, somehow determine the length that would take, then set the pagelength, and use the \newcommand to print the text. Thats the theory, I just don't know how to do that.. Commented Jun 2, 2011 at 17:37

1 Answer 1

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}.

3
  • 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. Commented Jun 2, 2011 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. Commented Jun 20, 2011 at 17:40
  • 2
    The automation is described here: tex.stackexchange.com/a/27057/7323 Commented Apr 14, 2014 at 14:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .