# Perfectly scale line, paragraph, image, anything up to textwidth

I want to scale a multi line text up to the available textwidth. I found something here: pgfplots: how can I scale to text width? and here: http://stackoverflow.com/questions/3106587/scale-an-equation-to-fit-exact-page-width and also, probably the most promising: How to scale a tikzpicture to \textwidth

I also want to scale a word up to the textwidth to produce a very simple poster and I'm doing something like this:

\centering\noindent\resizebox{\textwidth}{!}{Queue here!}


But that doesn't work for multi line solutions, i.e.

\centering\noindent\resizebox{\textwidth}{!}{Queue\\here!}


Would result in an error:

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...
l.12 ...ent\resizebox{\textwidth}{!}{Queue\here!}

Note that the above mentioned code doesn't work as expected if the text is more high than wide, i.e.

\centering\noindent\resizebox{\textwidth}{!}{!}


would not fit the exclamation mark onto the page, because it will grow too tall and way beyond the page.

As mentioned in How to scale a tikzpicture to \textwidth I also tried the adjustbox package. However, the following doesn't work as expected for two reasons: Firstly, it doesn't break lines, and secondly, it makes the text grow beyond the right border (according to the paper compile with the geometry package and showframe as argument).

\minsizebox{\textwidth}{!}{foo\\bar}


Just right now, I am looking for a solution that allows me to produce a poster type of document with multiple lines without wasting space, i.e. make it as big as possible. Obviously, I want to switch the paper as I usually do, namely just by changing i.e. "a4paper" into "a3paper" somewhere in the document.

Ideally, there is a generic solution that scales anything, including graphics, etc., up to the page. In my use case scenario, assuming that nothing else will be on the page is very reasonable. The ideal solution also works in corner cases like the above mentioned exclamation mark.

FWIW: Here is the code I have so far:

\documentclass[landscape]{minimal}
\usepackage[showframe,a4paper]{geometry}
\newcommand{\vstretch}[1]{\vspace*{\stretch{#1}}}

\begin{document}
\topskip0pt
\vstretch{1}
\minsizebox{\textwidth}{!}{foo\\bar}
%\centering\noindent\resizebox{\textwidth}{!}{!}%
\vstretch{1}
\end{document}


My fallback workflow up to now is something along the lines of:

Create a simple document, use pdfcrop and then pdfnup --nup 1x1 to scale it up.

-

The problem is that most multiline constructs have the current linewidth as the resulting width, so rescaling them does not make sense anyway. However, you can try the \resizebox on something like

\begin{tabular}{@{}c@{}}
foo\\
bar
\end{tabular}


and should have reasonable chances for success (the @{} take away the normal per-column padding).

-

\documentclass[landscape,a4paper]{article}

\usepackage{varwidth,graphicx}

\begin{document}
\setkeys{Gin}{keepaspectratio}

\noindent\resizebox*\textwidth\textheight{\begin{varwidth}{\textwidth}%
hello%
\end{varwidth}}

\noindent\resizebox*\textwidth\textheight{\begin{varwidth}{\textwidth}%
foo\\ bar%
\end{varwidth}}

\noindent\resizebox*\textwidth\textheight{\begin{varwidth}{\textwidth}%
aaa$1=2$bbb
\begin{enumerate}
\item foo
\item bar
\end{enumerate}%
\end{varwidth}}

\end{document}

-
Nice, but unfortunately, that doesn't do the multiline example, i.e. \noindent\resizebox\textwidth!{\begin{varwidth}{\textwidth}% foo\\ bar \end{varwidth}} doesn't work –  Frederick Nord May 11 '12 at 16:16
I gave a more complicated multiline example in my answer, and I have just confirmed again that \noindent\resizebox\textwidth!{\begin{varwidth}{\textwidth}% foo\\ bar% \end{varwidth}} works, I could update the code and image in the answer if need be? –  David Carlisle May 11 '12 at 16:35
image/code updated to show foo\\bar scaled –  David Carlisle May 11 '12 at 16:39
Sorry for not being entirely clear. It doesn't work for me in DIN A4 landscape mode. It grows too tall and the second line is not visible anymore. So it suffers from the exclamation mark problem mentioned in the question. –  Frederick Nord May 11 '12 at 16:59
Code updated with scaling for textheight and width but preserving aspect ratio –  David Carlisle May 11 '12 at 19:02