How to underline section-headings in LaTeX?

Mnementh picture Mnementh · Sep 8, 2009 · Viewed 43k times · Source

EDIT: As I see in the first answer, underline is the wrong word. I want a line under the section heading, separating the heading from the following text.

I want to separate section headings from the following text with a horizontal line. At the moment I use the following:

\newcommand{\tmpsection}[1]{}
\let\tmpsection=\section
\renewcommand{\section}[1]{\tmpsection{#1}\hrule\nobreak}

But that produces a line, that is too far away from the section-heading and to near to the following text. Has anyone a better idea?

Answer

Shirkrin picture Shirkrin · Sep 8, 2009

Rewriting your command like this should do the trick:

\newcommand{\tmpsection}[1]{}
\let\tmpsection=\section
\renewcommand{\section}[1]{\tmpsection{\underline{#1}}}

This will evaluate to

\section { \underline {#1} }

which in turn produces underlined section headings :)