\hfil in math mode [duplicate]

\documentclass[a4paper]{report}

\begin{document}
$\phantom{\ast}\hfil a\hfil\ast$
As you can see, the \verb"\hfil"s get ignored… or at least the one on the right does. But if I swap \verb"\phantom" and \verb"\ast", I get:
$\ast\hfil a\hfil\phantom{\ast},$
where the \verb"\hfil" is still being ignored. Therefore I infer both are being ignored.
\end{document}


Why does that happen?

marked as duplicate by David Carlisle math-mode StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Oct 10 '14 at 20:43

• It's the same as saying \hbox{a\hfil b}; display math material is typeset at its natural width, so glue doesn't stretch. – egreg Oct 10 '14 at 20:20

Saying \hfil is the same as saying \hskip 0pt plus 1fil or, in LaTeXspeak, \hspace{0pt plus 1fil}.

However, TeX uses the stretch component only if it has to. For instance, in

\hbox{a\hfil b} % Plain TeX
\makebox{a\hfil b} % LaTeX (or \mbox{a\hfil b})


the stretch component will do nothing and there will be no space between “a” and “b”. Conversely, a spacing will appear with

\hbox to 2cm{a\hfil b} % Plain TeX
\makebox[2cm][s]{a\hfil b} % LaTeX


because TeX wants to occupy the stated length.

A formula in display math is typeset at its natural width, so glue will use only the length component and not the stretch component. The length component for \hfil is zero.

If you want to fill all the available space, you should say

$\makebox[\displaywidth][s]{\displaystyle\phantom{*}a\hfil{*}}$


but it's surely better to say

$a\tag*{*}$


using amsmath features.