[Tex/LaTex] How to customize subsection in moderncv

moderncv

I want to add subsection in moderncv class which starts at the beginning of the line with a symbol such as a bullet or circ, or anything else which is in harmony with the moderncv layout. Or how can I draw a \hline (and in the same color of background)?

I have already read How to use subsubsection in "moderncv" class?, but this is not what I'm searching for.

What I have is something like this

enter image description here

with the code:

 \documentclass[11pt,a4paper,sans]{moderncv} 
 \moderncvstyle{casual} 
 \moderncvcolor{grey} 
 \usepackage{lipsum} 
 \usepackage[scale=0.75]{geometry}
 \firstname{xxx} 
 \familyname{xxx} 
 \title{Research Statement}

 \begin{document}
 \makecvtitle 

 \section{Section}

 \subsection{Subsection}

 \lipsum

 \end{document}

But, I want to have e.g. something like this

enter image description here

Best Answer

Well, the definition for commands \section and \subsection for style casual is

\RenewDocumentCommand{\section}{sm}{%
  \par\addvspace{2.5ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{section}{#2}%
  \cvitem[0ex]{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}%
  \par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading

\RenewDocumentCommand{\subsection}{sm}{%
  \par\addvspace{1ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{subsection}{#2}%
  \cvitem[0ex]{}{\strut\subsectionstyle{#2}}%
  \par\nobreak\addvspace{.5ex}\@afterheading}% to avoid a pagebreak after the heading

Now we can create a new command \mysubsection to get what you want. I just added the command for the horizontal rule with half the length of \hintscolumnwidth to the command and deleted the usage of command \cvitem, which builds the two columns for rule and text:

\makeatletter
\NewDocumentCommand{\mysubsection}{sm}{%
  \par\addvspace{1ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{subsection}{#2}%
  {\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{0.5\hintscolumnwidth}{0.95ex}}\quad}{\strut\subsectionstyle{#2}}%
  \par\nobreak\addvspace{.5ex}\@afterheading}% to avoid a pagebreak after the heading
\makeatother

Commands \makeatletter and \makeatother are needed because @ is used in the code above.

With the complete MWE

\documentclass[11pt,a4paper,sans]{moderncv}

\moderncvstyle{casual} % head [left,right] 2, body 1, foot 1
\moderncvcolor{grey} 

\usepackage{lipsum} 
\usepackage[scale=0.75]{geometry}

\makeatletter
\NewDocumentCommand{\mysubsection}{sm}{%
  \par\addvspace{1ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{subsection}{#2}%
  {\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{0.5\hintscolumnwidth}{0.95ex}}\quad}{\strut\subsectionstyle{#2}}%
  \par\nobreak\addvspace{.5ex}\@afterheading}% to avoid a pagebreak after the heading
\makeatother

\firstname{John} 
\familyname{Doe} 
\title{Research Statement}


\begin{document}
\makecvtitle 

\section{Section}

\subsection{Subsection}
\lipsum[1]

\mysubsection{Subsection}
\lipsum[1]

\end{document}

you get the result:

resulting pdf