TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create section headings that look like this:

-------------------- Some title --------------------

So a horizontal rule with text embedded in the middle. Should I use titlesec or fancyhdr packages for this? Does someone have an example?

share|improve this question
up vote 14 down vote accepted

Here is one way of doing this using titlesec. The vertically centered horizontal \hrulefill called \Vhrulefill was taken from Vertically centered horizontal rule filling the rest of a line?

enter image description here

\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage[explicit]{titlesec}% http://ctan.org/pkg/titlesec
\def\Vhrulefill{\leavevmode\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}
\section{First section}
\section{Second section}

Specifying the package option explicit allows you to have more control over the placement of the sectioning title via the #1 parameter in \titleformat. Of course, in this sense, you can also add a different space between the section and the horizontal rules (I've used ~ in my example). However, this modification (as well as the sectional formatting) may all be up to personal preference. I've also used \bfseries\large for the sectional headings which is different from what is defined in article.cls. Here are the defaults:

  • \section: \normalfont\Large\bfseries
  • \subsection: \normalfont\large\bfseries
  • \subsubsection: \normalfont\normalsize\bfseries
  • \paragraph: \normalfont\normalsize\bfseries
  • \subparagraph: \normalfont\normalsize\bfseries

\quad is the regular skip between the sectional number/counter and title/heading. It is defined as a horizontal skip of 1em, which is relative to the font size used - a good thing. Finally, if you want a regular rule at the baseline level, use \hrulefill instead of \Vhrulefill. Of course, any of the other methods described to provide a vertically centered \hrulefill should also work.

share|improve this answer
Nice answer, will upvote tomorrow. Maybe you should add some space (~) after/before \Vhrulefill. – lockstep Nov 1 '11 at 23:37
@lockstep: Thanks for this suggestion - I've incorporated it. – Werner Nov 1 '11 at 23:39
Excellent. Thanks! – Dennis Nov 2 '11 at 8:59
Maybe you should add \unskip after #1 to remove spaces at end of \section{...}, e.g. because of a line break before closing brace. – Schweinebacke Nov 7 '11 at 11:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.