# Horizontal line within a line of text

You may know that in moderncv there is a horizontal line at the left of each section. I want to print this at the right of the section title too, just like this:

My current code is as follows:

\documentclass[10pt,a4paper]{moderncv}
\moderncvtheme[blue]{classic}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
\usepackage[scale=0.92]{geometry}

\setlength{\hintscolumnwidth}{1.2cm}
\usepackage{helvet}

\firstname{\Huge Johnson}
\familyname{Green\vspace{-3mm}}

\title{\normalsize \color{black}Expertise in xxx and xxx.}
\mobile{\color{black}{\textbf{(987) 1234 5678}}}
\email{johnson.green@example.com}

\begin{document}
\maketitle

\section{\textbf{\textsc{Objective}}}
Seeking the XXX position in YYY that ...

\section{\textbf{\textsc{Education}}}
\cvitem{2010 - 2014}{ Ph.D, Z University}
\cvitem{2006 - 2010}{ B.A, M University}
\end{document}

-
Thank you for your question and welcome to the TeX.SX! Could you please extend your post and add a fully compilable (minimum working) example (MWE)? It would help the solvers a lot to start experimenting with your code. –  Malipivo Apr 16 '14 at 16:15

You can redefine \section to add the rule:

\documentclass{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
\usepackage[scale=0.92]{geometry}
\usepackage{helvet}

\setlength{\hintscolumnwidth}{1.2cm}
\newlength\TitleWd
\newlength\LeftRuleWd

\makeatletter
\RenewDocumentCommand{\section}{sm}{%
\settowidth\TitleWd{\sectionstyle{#2}}%
\setlength\LeftRuleWd{%
\dimexpr\textwidth-\TitleWd-2\separatorcolumnwidth-\hintscolumnwidth\relax}%
\phantomsection{}% reset the anchor for hyperrefs
\parbox[t]{\hintscolumnwidth}{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}}%
\hspace{\separatorcolumnwidth}%
\parbox[t]{\TitleWd}{\strut\sectionstyle{#2}}%
\hspace{\separatorcolumnwidth}%
\parbox[t]{\LeftRuleWd}{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\LeftRuleWd}{0.95ex}}}%
\makeatother

\name{John}{Doe}

\begin{document}

\section{Objective}
Test text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text
\section{Another title}
Test text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text

\end{document}


-
Thank you for this answer. However, I cannot compile it. The error: ! Undefined control sequence. l.14 \RenewDocumentCommand {\section}{sm}{% ? Process has been terminated ... –  C. Wang Apr 16 '14 at 16:42
@C.Wang I imagined so, seeing that you are still using the old commmands \familyname and \firstname; your version of moderncv is clearly outdated. Please update it. –  Gonzalo Medina Apr 16 '14 at 16:44
Okay, that was indeed the problem. Another question, is there a way to control the length of the line at right of the section name and make them align at the right end? –  C. Wang Apr 16 '14 at 17:44
@C.Wang please see my updated answer. Is it something like that what you need? If not, please let me know. –  Gonzalo Medina Apr 16 '14 at 17:49
Thank you so much! Awesome answer! That is what I want!!! ^_^ –  C. Wang Apr 16 '14 at 17:51

There is more simple solution:

\let\sectionOri=\section
\def\section#1{\sectionOri{#1 \ \leaders\hrule height7.1pt depth-1.8pt \hfill}}


Of course, this solution will not work correctly if you need to genereate the TOC. But I hope that TOC is not demanded in this application.

-