0

Is it possible to construct a box whose maximum width is specified, but in situations where that width is wider than the remaining width in a line, then the box just uses whatever space is left?

My use case is a book with fill-in-the-blanks. Each fill-in-the-blank has a width attached to it, like say 15em. It's great if the fill-in-the-blank is printed as a 15em wide box. But sometimes the fill-in-the-blank comes near the end of the line, and runs into the margin. I'd prefer it to just terminate as a shorter box. (And I'd prefer this over any kind of wrapping.)

With my use case in mind, here is something like what I am after in a sort of pseudo syntax: \framebox[min(15em, width of an hfill)]{\strut}.

3

One way would be to use \leaders.

enter image description here

\documentclass{article}

\def\zz{\leavevmode\vrule height 10pt\nobreak\leaders\vbox{\vskip-.4pt\hrule width .4pt\vskip 10pt \hrule\vskip-.4pt} \hskip 15em minus 15em \nobreak\hbox{\vrule height 10pt}}

\begin{document}

x\hspace{15em}X
zzzzzzzzzz \zz\   zzzzzzzzzzz \zz\ zzzzzzzzzzzzzz \zz\
zzzzzzzzzz \zz\   zzzzzzzzzzz \zz\ zzzzzzzzzzzzzz \zz

aaaa aaaaaaaaaaa aaaaaaaaaaaaaaaaa\zz

ZZZZZZZZZ aaaa aaaaaaaaaaa aaaaaaaaaaaaaaaaa\zz

ZZZZZZZZZZZZZZ aaaa aaaaaaaaaaa aaaaaaaaaaaaaaaaa\zz

ZZZZZZZZZZZZZZZZZZ aaaa aaaaaaaaaaa aaaaaaaaaaaaaaaaa\zz

\end{document}
1

You could use the linegoal pack­age which pro­vides the \line­goal pseudo length expanding to the re­main­ing length of the line.

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.