3

I am trying to make a document like this:

enter image description here

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
Imsong
  • 33

2 Answers2

6

enter image description here

\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}
David Carlisle
  • 757,742
3

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

enter image description here

\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
  \addvspace{.5\baselineskip}
}

\begin{document}

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

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

\end{document}

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.

Werner
  • 603,163