[Tex/LaTex] How to get underlined headings

cvformattingsectioningunderline

I would like to get underlined section headings that look like the lines under "Professional Experience" and "Education" in this example. I would preferably like to do this without switching to a resume-documentclass.

Also, if there is a way to have an linewidth underline under centered text and then have some smaller text centered below that underline, that would be great. (So, like underlining a name and then having contact information under the underline.)

Best Answer

I have adapted a reply given Underlining a whole line with a short text in its beginning But there is a small limitation the Section title should be smaller than linewidth.

\documentclass{article}
\usepackage{calc}  %% Needed for calculating remaining length. 
\usepackage{lipsum}

\newlength{\remaining}
\newcommand{\titleline}[1]{%
\setlength{\remaining}{\textwidth-\widthof{\textsc{#1}}}
\noindent\underline{\textsc{#1}\hspace*{\remaining}}\par}
\begin{document}

\titleline{Section Underlined}

\lipsum

\titleline{In case if I use a bigger line as a section title this command may behave weirdly }


\end{document}

MWE would have helped better.

Related Question