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.

Consider this:

\documentclass[a4paper,10pt]{article}
\usepackage[landscape,hmargin={1.2cm,1cm},vmargin=1cm,footskip=7mm]{geometry}
\begin{document}
\rule{5cm}{6cm}

\rule{5cm}{3cm}

\rule{5cm}{10cm}
\end{document}

The (MWE placeholder) boxes spread across two pages and a huge amount of whitespace is wasted. If they were shrunk very slightly, it would be possible to fit all the boxes on one page. Is there something which is like \adjustbox (in that it can scale material), but which can stretch to a certain degree in order to fit material well?

(I'm aware that one can fiddle with the raggedness of the page bottom, but that's not what I'm looking for, as in my real example a) my margins are already small and b) I'm already using adjustbox. Also the TeX is program-generated, so manually fiddling with parameters isn't an option.)

[Q. edited to clarify MWE.]

share|improve this question
    
Try \enlargethispage –  Aditya Dec 6 '12 at 15:44
    
@Aditya: see my a) above. –  Mohan Dec 6 '12 at 15:46

3 Answers 3

up vote 4 down vote accepted

You can use TeX's stretchy glue mechanism to calculate the box sizes on the next run.

enter image description here

\documentclass[a4paper,10pt]{article}
\usepackage[landscape,hmargin={1.2cm,1cm},vmargin=1cm,footskip=7mm]{geometry}
\makeatletter
\def\foo{%
\global\advance\fooc1
\hrule\@width\z@\@height\z@
\nobreak
\nointerlineskip
\hbox{\pdfsavepos
\edef\tmp{\write\noexpand\@auxout{%
\gdef\string\fooposa@\romannumeral\fooc{{\noexpand\the\noexpand\pdflastxpos}{\noexpand\the\noexpand\pdflastypos}}}}\tmp}%
\noindent\vbox to 0pt{%
\expandafter\ifx\csname fooposa@\romannumeral\fooc\endcsname\relax
\dimen@9.5cm\relax
\else
\dimen@\dimexpr
\expandafter\expandafter\expandafter\fooy\csname fooposa@\romannumeral\fooc\endcsname
-
\expandafter\expandafter\expandafter\fooy\csname fooposb@\romannumeral\fooc\endcsname\relax
\fi
\rule{5cm}{\dimen@}\vss}\par
\nobreak
\vskip 9.5cm plus .2cm minus 1cm\relax
\nobreak
\nointerlineskip
\hbox{\pdfsavepos
\edef\tmp{\write\noexpand\@auxout{%
\gdef\string\fooposb@\romannumeral\fooc{{\noexpand\the\noexpand\pdflastxpos}{\noexpand\the\noexpand\pdflastypos}}}}\tmp}%
\nobreak
\hrule\@width\z@\@height\z@
\penalty\z@}



\def\fooy#1#2{#2sp }
\newcount\fooc


\makeatother
\raggedbottom
\begin{document}



\foo

\smallskip

\foo

\smallskip

\foo

\end{document}
share|improve this answer

Not sure if this is can answer your question. Standard TeX \vbox tries to fit its contents to a given height, and to be able to do so, \baselineskip and \parskip should have some stratchability/shrinkability (if not, overfull and underfull vboxes are produced).

So in your case, if you define appropiately \parskip and \baselineskip, and put the content of your "boxes" inside a \vbox of a given height, the result will try to adapt to that height. Of course the difficult part is to estimate beforehand the required height, and this is why I think this answer is not useful.

Anyway, in order to clarify the underlying concepts, there is a MWE:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\long\def\content{
\parskip=1em plus 1ex minus 1ex
\baselineskip=11pt plus 2pt minus 4pt
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ac diam et
turpis imperdiet venenatis vitae sit amet dolor. [...]

Mauris volutpat est in tellus luctus in eleifend orci venenatis. Pellentesque 
gravida dictum augue, quis imperdiet metus gravida sed. 
}

% Two minipages side-to-side to compare their heights
\begin{minipage}[t]{.45\textwidth}
\vbox to 4cm{\content}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\vbox to 2.8cm{\content}
\end{minipage}
\end{document}

Result

share|improve this answer

It is not totally clear to me if you simply want the boxes reproduced or if you intend to replace them by for example graphics. I can see two solutions that works but it still requires specific numbers to be entered. Additional tweaking might yield even better results. The first set builds on the text height so it will scale with your text area.

\documentclass[a4paper,10pt]{article}
\usepackage[landscape,hmargin={1.2cm,1cm},vmargin=1cm,footskip=7mm]{geometry}
\usepackage{graphics}
\begin{document}

\resizebox{!}{.49\textheight}{\rule{5cm}{9.5cm}}

\resizebox{!}{.49\textheight}{\rule{5cm}{9.5cm}}

\resizebox{!}{.49\textheight}{\rule{5cm}{9.5cm}}

\resizebox{!}{.49\textheight}{\rule{5cm}{9.5cm}}

\newpage
\scalebox{.95}{\rule{5cm}{9.5cm}}

\scalebox{.95}{\rule{5cm}{9.5cm}}

\scalebox{.95}{\rule{5cm}{9.5cm}}

\scalebox{.95}{\rule{5cm}{9.5cm}}

\end{document}
share|improve this answer
    
Thank you. The boxes are placeholders -- they will be replaced with huge chunks of LaTeX code. –  Mohan Dec 6 '12 at 14:46
    
Ah --- the size of the 'boxes' can vary hugely; I just used 9.5cm to illustrate the problem. I'll fix the MWE. (Note that means scaling be a fixed factor won't help -- I really need some stretchiness.) –  Mohan Dec 6 '12 at 14:48

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.