1

I am trying to typeset a document with the following style for a section title:

The text is centred. There is a thick line on either side of the text extending to the margin The rule is vertically centred relative to the height of the title.

So far, I have tried using the titlesec package, and I have consulted similar queries other people have had about text with lines on either side. However, none of those were trying to define a section heading using this style.

This is the code that I got so far:

\makeatletter
   \def\vhrulefill{\leavevmode\leaders\hrule height 1ex depth \dimexpr0.4pt-0.7ex\hfill\kern\z@}
\makeatother

\titleformat{\section}[runin]%
{\LARGE\bfseries}%
{}{0pt}{\vhrulefill\space}[\space\vhrulefill\null]%

\begin{document}
\section{Foo}
Bar!
\end{document}

The end result of this has been that the text following the section does not break to a new line. Instead, it squeezes the title and the rule and encroaches upon the title.

Problem with the code I am getting so far

Could someone suggest a better way of defining the section heading with this kind of rule on either side?

Best wishes

1 Answers1

1

Simply use the block style with the explicit option:

\documentclass[11pt]{article}
\usepackage[explicit]{titlesec}

\makeatletter
   \def\vhrulefill{\leavevmode\leaders\hrule height 1ex depth \dimexpr0.4pt-0.7ex\hfill\kern\z@}
\makeatother

\titleformat{\section}[block]%
{\LARGE\bfseries}%
{}{0pt}{\vhrulefill\space#1\space\vhrulefill\null}%

\begin{document}

\section{Foo}
Bar!

\end{document}

enter image description here

Without the explicit optopn, you can use the runin style with the following code, but the vertical spacing after the section title won't be exactly the same:

\titleformat{\section}[runin]%
{\LARGE\bfseries}%
{}{0pt}{\vhrulefill\space}[\space\vhrulefill\null\break]%
Bernard
  • 271,350