[Tex/LaTex] Fancy style section titles for a resume

rulessectioning

I'm wondering if exists a way in LaTeX to create a section title style (for a resume) like this:

--------------------Education-------------------

There's for sure a wrong way, simply adding – sign but requires to write manually all characters… in that case why even using LaTeX? 🙂

What about \hline \line or something similar?

Best Answer

A nice exercise in low level TeX commands. :)

\documentclass{article}

\usepackage{lipsum} % mock text

%%% this is the important code
\newcommand{\myresumesection}[1]{%
  \par\addvspace{\bigskipamount}
  \noindent\myresumetitle{#1}\par
  \addvspace{\medskipamount}
}
\newcommand{\myresumetitle}[1]{%
  \makebox[\textwidth][s]{\large\bfseries
    \leaders\hrule height \dimexpr .5ex + 0.2pt\relax
                   depth -\dimexpr .5ex - 0.2pt\relax\hfill
    \ #1\ 
    \leaders\hrule height \dimexpr .5ex + 0.2pt\relax
                   depth -\dimexpr .5ex - 0.2pt\relax\hfill
  }%
}
%%% end of the important code

\begin{document}

\lipsum[2]

\myresumesection{Education}

\lipsum[1]

\end{document}

The mysterious instructions are:

  1. Make sure we are at the start of a paragraph
  2. Add some vertical space
  3. Print the title in a box
  4. End the line
  5. Add some vertical space

Now the more mysterious instructions

  1. The box is as wide as the lines
  2. Its content must be stretched to fill, in \large size and boldface type
  3. Print a rule at mid height of the letters without ascenders or descenders (1ex is precisely the height of an "x"); the rule is actually slightly higher, and its depth is negative, so the net effect is a rule 0.4pt thick
  4. Print the title surrounded by spaces
  5. Print another rule to fill

enter image description here

In order to avoid a page break just after the title, change the first definition into

\makeatletter
\newcommand{\myresumesection}[1]{%
  \par\addvspace{\bigskipamount}
  \noindent\myresumetitle{#1}\par
  \nobreak\vskip\medskipamount\@afterheading
}
\makeatother

(\@afterheading is the magic trick that LaTeX uses for section titles)