Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In the memoir manual on page 183 ,this example is given:

\begin{figure}
\centering
\hspace*{\fill}
{ILLUSTRATION 1} \hfill {ILLUSTRATION 2}
\hspace*{\fill}
\caption{Example float with two illustrations}
\label{fig:mult1}
\end{figure}

I have tried to figure out, what the difference between \hspace*{\fill} and \hfill is!?

The \hfill definition and \hspace definition did not help me much.

share|improve this question

2 Answers 2

up vote 21 down vote accepted

Using your code snippet as an example, \centering only has an impact on the \caption. However,

\hspace*{\fill}
{ILLUSTRATION 1} \hfill {ILLUSTRATION 2}
\hspace*{\fill}

is meant to set ILLUSTRATION 1 and ILLUSTRATION 2 even distributed across \textwidth:

enter image description here

\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\begin{document}
\begin{figure}
\centering
\hspace*{\fill}
{ILLUSTRATION 1} \hfill {ILLUSTRATION 2}
\hspace*{\fill}
\caption{Example float with two illustrations}
\label{fig:mult1}
\end{figure}
\end{document}

However, replacing \hspace*{\fill} with \hfill, the space from the right margin is "gobbled":

enter image description here

\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\begin{document}
\begin{figure}
\centering
\hfill%\hspace*{\fill}
{ILLUSTRATION 1} \hfill {ILLUSTRATION 2}%
\hfill%\hspace*{\fill}
\caption{Example float with two illustrations}
\label{fig:mult1}
\end{figure}
\end{document}

giving value to the command definition for \hspace*:

LaTeX removes horizontal space that comes at the end of a line. If you don't want LaTeX to remove this space, include the optional * argument. Then the space is never removed.

An alternative to use if \hfill is more intuitive than \hspace*{\fill}, is to insert dummy text (like \null or \mbox{}) at the (start and) end of the line. That way the \hfill will always have "something to infinitely stretch against":

\null\hfill%
{ILLUSTRATION 1} \hfill {ILLUSTRATION 2}%
\hfill\null%

In the above examples, showframe merely highlighted the text block.

share|improve this answer
1  
Is \hspace{\fill} and \hfill the same? Why is there no \hfill*? –  Hans-Peter E. Kristiansen Feb 27 '12 at 22:53
    
Why do you need \null at the start of the line? I can't see the difference with or without. –  adl Apr 15 at 14:24
    
@adl: You don't need it at the start of the line. It just provides for symmetrical coding. –  Werner Apr 15 at 20:27

There is a very good discussion and answers at What is the difference between 'fil' and 'fill'?.

As related to the specifics in your question \hfill is a TeX primitive that expands to,

 \hfill = \hskip 0pt plus 1fill minus 0pt

whereas \hspace*{\fill}, is a LaTeX macro, which leaves a space equal to a 1fill. The star version of the command is used if the glue is to be inserted at the beginning of a line.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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