Why does the following command not produce a horizontal rule filling the space until the end of the line?
Hello \rule[0.5em]{\fill}{1pt}
It is my understanding that this should print the text “Hello
” followed by a horizontal rule that extends until the end of the line, analogously to the macro \hfill
which is effectively equivalent to \hspace\fill
. – But in effect, this command just produces the text “Hello
”, no rule.
I am aware that the effect can be produced by \hrulefill
but it can’t be used here because I want a raised rule and \hrulefill
doesn’t work together with \raisebox
and I want my rule to hang above the baseline (at best in the middle of the line).
I don't have a satisfying answer as to why the command you presented doesn't work, but I can offer an effective workaround. Put
% Raised Rule Command:
% Arg 1 (Optional) - How high to raise the rule
% Arg 2 - Thickness of the rule
\newcommand{\raisedrule}[2][0em]{\leaders\hbox{\rule[#1]{1pt}{#2}}\hfill}
into your document's preface, and then you can accomplish what you were hoping to with:
Hello \raisedrule[0.5em]{1pt}