# edit the minimum length of \hfill

Once again I have a pretty special problem: I'd like to edit the minimum length of \hfill. According to de.wikibooks it is a TeX primitive. Therefore, I assume, that it can't be edited.

What is it for? I want to squeeze several boxes into one \textwidth no matter what. It should be similar to \mbox{}, but not broader than the textwidth.

There is a possibility the make this by counting the boxes and use \hspace with a (maybe) negative value which is calculated by the number of boxes. But this would be pretty complicated and requires an aux-file.

MnWE for explanation:

%This box should not be wider than \textwidth. It must be squeezed to \textwidth
\mbox[\textwidth]{ %There is no such instruction \mbox[width]{content}
\parbox{0.5\textwidth}{some Text}
\hfill
\parbox{0.5\textwidth}{some Text}
\hfill
\parbox{0.5\textwidth}{some Text}
}
%to fit, hfill must be -0.25\textwith, but it refuses to get negative, so this box will be wider than the text area.

• your question isn't at all clear (what has a glue like \hfill got to do with box sizes?) but \hskip 0pt plus 1cm is like \hfill but stretches between 0pt and 1cm – David Carlisle Apr 26 '16 at 13:06
• @DavidCarlisle: If I have three boxes in one line with 0.5\textwidth, they are 0.5\textwidth too large for one line. \hfill will be its minimum, which I think is 0pt, but it should be -0.25\textwidth. I'll add a MnWE. – MaestroGlanz Apr 26 '16 at 13:11
• use \hss then that will shrink to arbitrary negative size or stretch arbitrarily large – David Carlisle Apr 26 '16 at 13:14
• %There is no such instruction \mbox[width]{content} of course there is:-) \mbox is short form of \makebox which has exactly that form, \makebox[width]{content} – David Carlisle Apr 26 '16 at 13:17
• note that you have word spaces as well as \hfill before and after the boxes due to missing % at ends of lines – David Carlisle Apr 26 '16 at 13:18

\hss "horizontal shrink/stretch" will shrink to negative sizes if needed or stretch as much as needed, as requested in comments.

\documentclass{article}

\begin{document}

\begin{flushleft}
\makebox[\textwidth][s]{%%%%
\parbox{0.5\textwidth}{some Text}%%%%
\hss
\parbox{0.5\textwidth}{some Text}%%%%
\hss
\parbox{0.5\textwidth}{some Text}%%%%
}
\end{flushleft}

\end{document}

• It refuses to get negative. The least value is 0pt as well. – MaestroGlanz Apr 26 '16 at 13:32
• @MaestroGlanz You have to use \makebox[\textwidth][s]{...} to remove the centering glue at either side. – egreg Apr 26 '16 at 13:35
• I used your example and it worked. Though mine was identical. I had some \nopagebreaks in there. They probably messed it up. I don't know, but now it works. – MaestroGlanz Apr 26 '16 at 13:47

Here I introduce \Hfill which has a minimum spacing of \Hfillkern (EDITED per OP's comment), but otherwise it is an \hfill. It is defined as

\def\Hfill{\hspace{\Hfillkern}\hfill}


The user may specify the \Hfillkern length via \setHfillkern{}.

Here is the MWE, with \Hfillkern set to -.25\textwidth.

\documentclass{article}
\parskip 1em
\parindent 0pt

\newcommand\setHfillkern[1]{\def\Hfillkern{#1}}
\setHfillkern{-.25\textwidth}
\def\Hfill{\hspace{\Hfillkern}\hfill}
\def\X{\fbox{\makebox[.25\textwidth]{This is my box}}}
\begin{document}

\X\Hfill \X

\X\Hfill \X\Hfill \X

\X\Hfill \X\Hfill \X\Hfill \X

\X\Hfill \X\Hfill \X\Hfill \X\Hfill \X

\X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \X\Hfill \
\end{document}


As long as \Hfillkern is the negative width of the boxes being set, one should be able to squeeze an arbitrarily large number of boxes on the line, which seems to be the OP's request.

On the other hand, if the box width is larger in magnitude than the \Hfillkern, then there will be an upper limit to the number of boxes that will be able to be placed on the line.

• Nice one, but it doesn't work with negative values. – MaestroGlanz Apr 26 '16 at 13:22
• @MaestroGlanz Are you commenting on the edited version of my answer? What negative value am I not accounting for? – Steven B. Segletes Apr 26 '16 at 13:24
• i.e. \hspace{-30pt}\hfill – MaestroGlanz Apr 26 '16 at 13:31
• @MaestroGlanz I still do not understand your comment. As I point out at the end of my answer, the negative \hspace associated with the \Hfill must match the box width being placed on the line, in order to allow an arbitrary number of boxes to be placed on the line. If it would be helpful, I can make the leftward shift of the \Hfill` a user-specifiable parameter. – Steven B. Segletes Apr 26 '16 at 13:33
• This is very useful. Although, I marked the other answer as solution, since it is first answer and more understandable to non-TeX-safe people. – MaestroGlanz Apr 26 '16 at 13:50