[Tex/LaTex] How to create a header line after text

cvheader-footersectioning

text followed by a header line

Hi,

I am looking to recreate the style above for a resume. For the heading of sections in the resume, I want the section name (in the example above – Education) to be followed by a header line filling up the rest of the line.

It would be great if someone could tell me how to do it.

Another example is included below. In this one, the text appears in the middle, surrounded by header lines on both sides.

text followed and preceded by header line segments

Best Answer

Here's one possibility using the titlesec and xhfill packages:

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{xhfill}
\usepackage{lipsum}% just to generate text for the example

\titleformat{\section}
  {\normalfont\Large\bfseries}{}{0em}{#1~\xrfill[0.3ex]{1.5pt}}

\begin{document}

\section{Education}
\lipsum[4]

\end{document}

enter image description here

And the other style:

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{xhfill}
\usepackage{lipsum}% just to generate text for the example

\titleformat{\section}
  {\normalfont\Large\bfseries\filcenter}{}{0em}{\xrfill[0.3ex]{1.5pt}~#1~\xrfill[0.3ex]{1.5pt}}

\begin{document}

\section{Education}
\lipsum[4]

\end{document}

enter image description here

If titles are long, then one can use a minipage or variable width (through the varwidth) package, to produce something like:

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{xhfill}
\usepackage{varwidth}
\usepackage{lipsum}% just to generate text for the example

\newlength\mylen

\titleformat{\section}
  {\normalfont\Large\bfseries}{}{0em}
  {\begin{varwidth}{.7\linewidth}\raggedright#1\end{varwidth}~\xrfill[0.3ex]{1.5pt}}

\begin{document}

\section{Education}
\lipsum[4]
\section{Education and other extra activities}
\lipsum[4]

\end{document}

enter image description here

Something analogous can be done for the other style:

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{xhfill}
\usepackage{varwidth}
\usepackage{lipsum}% just to generate text for the example

\newlength\mylen

\titleformat{\section}
  {\normalfont\Large\bfseries\filcenter}{}{0em}
  {\xrfill[0.3ex]{1.5pt}~\begin{varwidth}{.75\linewidth}\centering#1\end{varwidth}~\xrfill[0.3ex]{1.5pt}}

\begin{document}

\section{Education}
\lipsum[4]
\section{Education and some other extra~activities}
\lipsum[4]

\end{document}

enter image description here

If both styles are to be applied in the same document, define commands for each style ans use them, as many times as required, to switch where needed:

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{xhfill}
\usepackage{varwidth}
\usepackage{lipsum}% just to generate text for the example

\newcommand\Ruled{%
\titleformat{\section}
  {\normalfont\Large\bfseries}{}{0em}
  {\begin{varwidth}{.7\linewidth}\raggedright##1\end{varwidth}~\xrfill[0.3ex]{1.5pt}}
}
\newcommand\Centered{%
\titleformat{\section}
  {\normalfont\Large\bfseries\filcenter}{}{0em}
  {\xrfill[0.3ex]{1.5pt}~\begin{varwidth}{.75\linewidth}\centering##1\end{varwidth}~\xrfill[0.3ex]{1.5pt}}
}

\begin{document}

\Ruled
\section{Education}
\lipsum[4]
\Centered
\section{Education and some other extra~activities}
\lipsum[4]

\end{document}

enter image description here

Adjust the settings according to your needs. I didn't use small capitals since some fonts don't support bold-faced small caps.