# Rubber width \parbox

I am trying to create a rubber width \parbox in LaTeX so that the whole line will be evenly filled. It is for creating a mad-libs style fill in command that will stretch a certain amount of width. I tried the following:

\newcommand{\libfillin}[2]
{
\parbox[t]{#1 plus50pt minus50pt}{
\rule[-3pt]{\linewidth}{0.5mm}
\parbox[t][1pt][b]{\linewidth}{\small \centering
\emph{#2}}\vspace{2pt}\hfill\\
}
}


However, this results in the text plus50pt minus50pt being printed and invalid width for the parboxes. How might I fix this?

• What do you mean by "the whole line will be evenly filled"? Horizontally? Then you could/should just use \noindent\parbox{\linewidth}{...}. – Werner Jun 15 '15 at 18:43
• So that the text will remain justified. – user530873 Jun 15 '15 at 18:45
• your question is completely unclear however perhaps the varwidth environment from the package of that name is what you are looking for, – David Carlisle Jun 15 '15 at 18:48
• also what effect do you intend \vspace{2pt}\hfill\\  to have? – David Carlisle Jun 15 '15 at 18:58
• This answer might be related to your issue. – GuM Jun 15 '15 at 21:55

I'd never heard of mad-libs but google leads to Wikipedia that suggests that you want an output like

\documentclass{article}

\def\zz#1{%
\mbox{}%
\setbox0\hbox{#1}%
\nobreak\hskip-.5\wd0 plus -10pt minus -10pt\relax
\makebox[0pt]{\raisebox{-7pt}{\small\itshape#1}}%
\nobreak\hskip.5\wd0 plus 10pt minus 10pt\relax\kern0pt
}

\begin{document}


• @smpl I take the approximate length from the length of the "classification" at full size (the \setbox0\hbox{#1} at the start, you could have an extra argument that put the answer in there instead then it would use the length of that. or make the extra argument a length and use that instead of \wd0 in the leader and hskips. – David Carlisle Jun 16 '15 at 8:13
• \nobreak before the first \leaders prevent a line break at this place, but the line break might be at the start of the space before, then the \leaders gets discarded. Something like \null before the \leaders prevents this. – Heiko Oberdiek Jun 27 '15 at 12:20
• @HeikoOberdiek yes thanks I switched to \mbox – David Carlisle Jun 27 '15 at 13:19