# Underlining a whole line with texts at different spots

I would like to underline the whole line with texts anywhere I choose on the line. I found this answer, which is almost what I want. I tried

\titleline{homework \hfill assignment}


but it does not output what I expect. Why is that? Also, here is a visualization of what I want to produce:

There are a large number of ways one can achieve this. Here's one using a tabular for the "underline":

\documentclass{article}

\newcommand{\titleline}[3]{%
\par\noindent
\begin{tabular}{ @{} p{\linewidth} @{} }
\makebox[0pt][l]{#1}\hfill
\makebox[0pt][c]{#2}\hfill
\makebox[0pt][r]{#3} \\
\hline
\end{tabular}}

\begin{document}

\titleline{Left}{Center}{Right}

\titleline{Very long left}{Medium center}{R}

\end{document}