# Underline text with === (SETEX style)

I'm trying to recreate the typewriter look.

How to make \underline{sometext} work like SETEX-style section marker?

The intended use is with monospaced/typewriter fonts for lines with plenty of space beneath them (like section headings).

Illustration of desired effect below.

For example using \halign and \leaders primitives:

\def\underlined#1{\vtop{\tt\halign{##\cr#1\cr\leaders\hbox{=}\hfill\cr}}}

Text: \underlined{Odwolanie upowaznienia}

\bye

• Neat solution with \leaders – DG' Jan 15 at 16:51
• How do you adjust the distance of the underlining from the underlined text? – Marek Kowalczyk Jan 18 at 23:14
• @MarekKowalczyk Using \noalign{\kern-1pt} (-1pt just for example) inserted between second \cr and \leaders in the macro. – wipet Jan 19 at 13:19
• This works: \def\underlined#1{\vtop{\halign{##\cr#1\cr\noalign{\kern-6pt}\leaders\hbox{=}\hfill\cr}}} – Marek Kowalczyk Jan 21 at 13:47

The real typewriter look can be achieved by setting a number of = below the title. Here is an example with \section:

\documentclass{article}

\usepackage{xstring}
\usepackage{multido}
\usepackage[explicit]{titlesec}
\usepackage[default]{sourcecodepro}

\newcommand\setex[1]
{#1 \\ \StrLen{#1}[\len]\multido{}{\len}{=}}

\titleformat{\section}
{\normalfont\filcenter}{}{0pt}{\setex{#1}}

\begin{document}

\section{Test}

Lorem ipsum...

\end{document}


This will not work for really long section titles.

• How do you adjust the distance of the underlining from the underlined text? – Marek Kowalczyk Jan 18 at 23:14
• It's just a simple line of text, you can try adjusting the baseline or something like that – DG' Jan 19 at 8:57
• This works: \newcommand\setex[1]{#1 \\ \StrLen{#1}[\len]\kern-4pt\multido{}{\len}{=}} – Marek Kowalczyk Jan 21 at 13:45