5

Suppose I have some title text that I format as follows:

\begin{center}
 {\small Brief Notes on}\\[-0.2em]
 Some Topic of Questionable Interest\\[-0.6em]
 \rule{12em}{0.75pt}
\end{center}

This produces two lines of text with a 12em-wide rule beneath them.

Is there a way to get LaTeX to automatically adjust the length of the rule to be equal to that of the bottom line of text (plus some user-specified offset)?

Ubiquitous
  • 2,566

2 Answers2

3

Here's a way to achieve this using tikzmark as suggested by Jubobs:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\begin{document}
\begin{center}
 {\small Brief Notes on}\\[-0.2em]
 \tikzmark{leftend}Some Topic of Questionable Interest\tikzmark{rightend}
  \begin{tikzpicture}[overlay, remember picture]
      \draw(leftend.south west) -- (rightend.south east);
  \end{tikzpicture}
\end{center}
\end{document}

enter image description here

Replacing south west and south east with south eliminates the small offset between the line ends and the edge of the text.

Ubiquitous
  • 2,566
2

use a tabular:

\documentclass{article}
\begin{document}
\begin{center}
\begin{tabular}{@{}c@{}}
\small Brief Notes on\\[-0.2em]
 Some Topic of Questionable Interest\\\hline
\end{tabular}
\end{center}

\end{document}

enter image description here