11

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:

Mockup of desired output

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{[email protected]}

\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}
1
  • 1
    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, 2014 at 16:15

2 Answers 2

11

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}%
  \par\addvspace{2.5ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{section}{#2}%
  \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}}}%  
  \par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading
\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}

enter image description here

5
  • 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, 2014 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. Apr 16, 2014 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, 2014 at 17:44
  • @C.Wang please see my updated answer. Is it something like that what you need? If not, please let me know. Apr 16, 2014 at 17:49
  • Thank you so much! Awesome answer! That is what I want!!! ^_^
    – C. Wang
    Apr 16, 2014 at 17:51
2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .