2

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?

enter image description here

  • 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
2

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
  \quad
  #1% the title
  \quad
  \leaders\hrule height \dimexpr 0.5ex+0.2pt\relax depth -\dimexpr 0.5ex-0.2pt\relax\hfill
}

\begin{document}

\lipsum[3]

\section{Areas of Expertise}

\lipsum[1-2]

\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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