views:

3570

answers:

4

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?

+2  A: 

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 :)

Shirkrin
It will also underline the section names in the table of contents, which is presumably *not* what you want.
Will Robertson
I see I asked my question bad. I don't want a underline in this sense, I really want a line separating the heading from the following text.
Mnementh
+3  A: 

You can do this with the \sectionrule command in the sectsty package.

Rob Hyndman
sectsty does what I want, but I have another problem: I have a book (scrbook-documentclass) and using the command \part. That does no longer work with sectsty. Any advices?
Mnementh
A: 

You might take a look at the LaTeX \rule command:

\rule[raise-height]{width}{thickness}

However, that's an inline (horizontal) command, so you'll have to use some trickery to get it at the right position and size (\noindent and \textwidth should help a little).

Otherwise, you can use the following plain TeX

\smallskip
\hrule height 2pt
\smallskip

It doesn't really fit in the LaTeX syntax, but it works like a charm, and is guaranteed to span the entire text width.

Ruben
+1  A: 

Use the titlesec package. The titlesec manual is here, and plenty of other resources are available elsewhere.

kquinn