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:

    \parbox[t]{#1 plus50pt minus50pt}{
        \parbox[t][1pt][b]{\linewidth}{\small \centering

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
  • 1
    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

enter image description here


\nobreak\leaders\hrule\hskip\wd0 plus 20pt minus 20pt
\nobreak\hskip-.5\wd0 plus -10pt minus -10pt\relax
\nobreak\hskip.5\wd0 plus 10pt minus 10pt\relax\kern0pt



\zz{exclamation}! he said \zz{adverb} as he jumped into his convertible
\zz{noun}  and drove off with his \zz{adjective} wife.

  • This solution is OK, however there is no way to specify the approximate length (or relative length) of the line. For example, "reason" is a short word, but may require a lot of space to write in. – user530873 Jun 16 '15 at 0:32
  • @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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.