# How to stretch table or minipage to fill remaining space?

I am trying to make a document like this:

Since there's quite a lot of such sections, I want to make a new command like \textwithline{}{} so I can then type

Author: \textwithline{Joe Shmoe}{First name, Last name}

This author's editor: \textwithline{Billy Willy}{First name, Last name}


in my document.

Note the important features:

• The line must fill all available remaining space
• The text above and below the line must be centered on the line
• The text on the left is variable length (or may be blank)

What is a good way of making such a command? I have tried:

• tabular with \hfill but it doesn't actually stretch the table
• tabular* but it doesn't "give room" to the text on the left
• minipage but that requires me to hard code width every time
• \uline{\hfill Billy Willy \hfill}{\hfill First name, Last name \hfill} with \centering but then text below line is not centered on the line, but on the page
• – Werner Aug 8 '18 at 19:58

\documentclass{article}

\newcommand\textwithline[2]{{%
\setlength\parfillskip{0pt}%
\hrulefill
\raisebox{5pt}{\makebox[0pt]{#1}}%
\raisebox{-12pt}{\makebox[0pt]{#2}}%
\hrulefill
\par
\bigskip}}

\begin{document}

Author: \textwithline{Joe Shmoe}{First name, Last name}

This author's editor: \textwithline{Billy Willy}{First name, Last name}

\end{document}


Here is an option using linegoal to calculate the remaining width of the line (given by \linegoal).

\documentclass{article}

\usepackage{linegoal}

\newcommand{\textwithline}[2]{%
\begin{minipage}[t]{\linegoal}
\centering\strut #1 \\[-.7\baselineskip]
\hrulefill \\[-.1\baselineskip]
\centering\small\footnotesize #2
\end{minipage}\par

Since linegoal uses a label-ref-like system (thanks to zref), any changes in width would require you to compile at least twice before the width settles.