# Create a heading with a horizontal bar interrupted by text

I'm trying to create a command that creates text to look like the image attached.

Specifically, I want a develop a command, say we call it "CenterTextWithLine", such that I type: \CenterTextWithLine{Areas of Expertise} And I get the appropriate formatting shown in the attached image.

Currently I type the following:

\rule{0.325\textwidth}{1pt} Areas of Expertise \rule{0.325\textwidth}{1pt}

but I have to manually adjust the width of each ruling.

How do I go about creating a command that takes a text string of variable length, and calculates appropriate horizontal rule lengths to put on each side of the text?

• Is it for a section title or something like that? – Bernard Oct 4 '15 at 22:59
• @Bernard yes indeed – Joe Oct 5 '15 at 1:56
• You have powerful tools for that with titlesec, if you use a standard class. – Bernard Oct 5 '15 at 1:58

An almost straightforward modification of one of my answers

\documentclass{article}
\usepackage{titlesec}
\usepackage{lipsum}

\titleformat{\section}
{\scshape}
{}
{0pt}
{\betweenrules}

\titlespacing*{\section}
{0pt}
{2ex}
{1ex}

\newcommand{\betweenrules}[1]{%
\leaders\hrule height \dimexpr 0.5ex+0.2pt\relax depth -\dimexpr 0.5ex-0.2pt\relax\hfill
#1% the title