I want to write a command or similar that allows me to rescale a given paragraph to fit a given frame, keeping the aspect ratio. The problem is that the paragraph is usually manually set and not automatically wrapped (and thus I do not know its width).
To give an example, using the adjustbox
package, I can combine minsizebox
and maxsizebox
to define almostwhatiwant
in the following way (the boxes generated with displayconstraint
are just for illustration):
\documentclass{article}
\usepackage{adjustbox}
\newcommand{\displayconstraint}[1]{\fbox{\begin{minipage}[l][3cm]{5cm} #1 \end{minipage}}}
\newcommand{\almostwhatiwant}[1]{\maxsizebox{5cm}{3cm}{\minsizebox{5cm}{3cm}{#1}}}
\begin{document}\noindent
\displayconstraint{\almostwhatiwant{test}} % example 1
\displayconstraint{\almostwhatiwant{t}}\\ % example 2
\displayconstraint{\almostwhatiwant{test\\test test}} % example 3
\displayconstraint{\almostwhatiwant{\parbox{\linewidth}{test\\test test}}} % example 4
\end{document}
renders the following:
The first two examples (top row) are rendered as desired, but as soon as I want to make linebreaks, I encounter the problem that I have to use a paragraph-like environment (otherwise, the third example happens), for which I have to specify a linewidth. This allows me to format the text in the way I want, but its width as used by the rescaling boxes is now the specified linewidth and thus the result is dissatisfactory (example 4).
I am aware of many other approaches to this problem, but they all eventually fail due to similar reasons or require me to do something manually (like detecting the longest line of the paragraph).
I could fix this problem, if I could somehow detect the actual width of a paragraph or crop a paragraph to its actual content.
\begin{tabular}{@{}l@{}}zzz\\zzz\end{tabular}
to make a box as wide as the longest line – David Carlisle Aug 11 '14 at 9:11