Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to customize \section style in order to have the following title (forget the horizontal line) :

title \section

I imagine that I need to modify the following definition:

\renewcommand*{\section}[1]{%
  \par\addvspace{2.5ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{section}{#1}%
  \strut\sectionstyle{#1}%
  {\color{color1}\hrule}%
  \par\nobreak\addvspace{1ex}\@afterheading}

The code I am using is:

\section{CORE COMPETENCIES}

Can you tell me how?

share|improve this question
    
Excuse me! Is it ok, now? –  Marco Dec 3 '12 at 22:24
    
no need to apologize :-) Yes, it's OK now. Thank you very much! –  Gonzalo Medina Dec 3 '12 at 22:28
add comment

1 Answer

up vote 1 down vote accepted

Here's one possibility using \colorbox and a \parbox:

\documentclass{moderncv}
\moderncvtheme{classic}

\firstname{John}
\familyname{Doe}

\makeatletter
\renewcommand*{\sectionstyle}[1]{\colorbox{color1}{%
  \parbox[t]{\dimexpr\textwidth-2\fboxsep\relax}{\sectionfont#1}}}
\renewcommand*{\section}[1]{%
  \par\addvspace{2.5ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{section}{#1}%
  \strut\sectionstyle{#1}%
  \par\nobreak\addvspace{1ex}\@afterheading}
\makeatother

\begin{document}

\makecvtitle
\section{CORE COMPETENCIES}

\end{document}

enter image description here

Perhaps this modification follows more accurately the image in the question (no horizontal space between the colored box and the text and bold-faced text); I also added \MakeUppercase to \sectionstyle:

\documentclass{moderncv}
\moderncvtheme{classic}

\firstname{John}
\familyname{Doe}

\makeatletter
\renewcommand\sectionfont{\bfseries\large}
\renewcommand*{\sectionstyle}[1]{{%
  \setlength\fboxsep{0pt}%
  \colorbox{color1}{%
    \parbox[t]{\textwidth}{\sectionfont\rule[-.5ex]{0pt}{2.8ex}\MakeUppercase{#1}}}}}
\renewcommand*{\section}[1]{%
  \par\addvspace{2.5ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{section}{#1}%
  \sectionstyle{#1}%
  \par\nobreak\addvspace{1ex}\@afterheading}
\makeatother

\begin{document}

\makecvtitle
\section{Core competencies}

\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.