LaTeX \rule filling the line
The horizontal rule of 1pt height and raised by 1.5pt.
Hello \leaders\vrule height 2.5pt depth -1.5pt \hfill \null
There is a package called ulem which does this
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass{article}
\usepackage[normalem]{ulem}
\begin{document}
normal text \uline{\textit{underline text}\hfill}
\end{document}
which will produce
For your curiosity, the option normalem
for package ulem prevents ulem to produce extra underline with \em
or \emph
.
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}