# Customizing \section in moderncv

I'd like to customize my moderncv a bit. For my sections I want a color fade in the headings. For this purpose I got this code in Latex:

\documentclass{article}
\usepackage{tikz}
\tikzset{
zero sep/.style = {inner sep=0pt, outer sep=0pt},
}

\newcommand\tikzsection[1]{%
\pgfmathsetmacro\randref{rand}
\node[fill=white,anchor=south east,zero sep,minimum width=5cm,minimum height=2.5mm] (box node){};
\node [text=white,anchor=base west,text depth=5pt,text height=12pt,zero sep,
font=\normalfont\Large\bfseries,right=10pt of box node,
text width=5.9cm,align=left] (text node) {#1};
\node [fit={(box node)(text node)
},zero sep] (myfit) {};
\path let \p1=(myfit.south west), \p2=(myfit.north east), \n1={\x2-\x1}, \n2={\y2-\y1} in
\pgfextra{\xdef\lenx{\n1} \xdef\leny{\n2}};
\section[#1]{%
\begin{tikzpicture}[baseline=.5*5pt-.5*12pt]
(-.5*\lenx,-.5*\leny) rectangle ++(\lenx,\leny);
\end{tikzpicture}
}
}
\pagestyle{empty}

\begin{document}
\tikzsection{First section}
Some text
\tikzsection{Secoooooond segtion}
Some text
\tikzsection{Short}
Some text

\end{document}


I tried to include this in my moderncv but obviously I can't just use it like that since the \section command is already defined in moderncv. I tried to redefine it in moderncv and moderncvstyleclassic but it still gives me errors. Do you know what I have to do to use it in my moderncv instead of \section?

This is how the \section command is defined in moderncv:

\renewcommand*{\section}[1]{%
\phantomsection{}% reset the anchor for hyperrefs
\strut\sectionstyle{#1}%
{\color{color1}\hrule}%


where \sectionstyle is again an own command (sorry I don't have access right now to the files of moderncv)

Here's one possibility:

\documentclass{moderncv}
\usepackage{tikz}

\tikzset{
zero sep/.style = {inner sep=0pt, outer sep=0pt},
}

\moderncvstyle{classic}

\makeatletter
\renewcommand\section[1]{%
\phantomsection{}% reset the anchor for hyperrefs
\pgfmathsetmacro\randref{rand}
\node[fill=white,anchor=south east,zero sep,minimum width=5cm,minimum height=2.5mm] (box node){};
\node [text=white,anchor=base west,text depth=5pt,text height=12pt,zero sep,
font=\normalfont\Large\bfseries,right=10pt of box node,
text width=5.9cm,align=left] (text node) {\strut#1\strut};
\node [fit={(box node)(text node)
},zero sep] (myfit) {};
\path let \p1=(myfit.south west), \p2=(myfit.north east), \n1={\x2-\x1}, \n2={\y2-\y1} in
\pgfextra{\xdef\lenx{\n1} \xdef\leny{\n2}};
\begin{tikzpicture}[baseline=.5*5pt-.5*12pt]
(-.5*\lenx,-.5*\leny) rectangle ++(\lenx,\leny);
\end{tikzpicture}%
}
\makeatother

\firstname{John}
\lastname{Doe}

\begin{document}

\section{First section}
Some text
\section{Second section with a long title to see what happens when spanning more than one line}
Some text
\section{Short}
Some text

\end{document}


The resulting document:

Notice, however, that the code you are trying to use will produce unexpected results for long titles (see what happens with the long title for the second section).

• Maybe you can answer me also another question that just popped up. What you suggested is working fine (thanks for that) but I included in my cv the moderntimelinepackage and the \usetikzlibrary{positioning} destroys now my timeline labels and makes them floating around wildly. Is there a way that I can use \usetikzlibrary{positioning} without affecting my moderntimeline? – Adrian Pfeifle Dec 12 '14 at 17:48
• BTW the unexpected results you mentioned come from text width=5.9cm if you increase that number you can adjust the length of the headings – Adrian Pfeifle Dec 12 '14 at 17:58
• @Adrian Pfeifle Regarding the moderntimeline issue, I think it's better to open a fresh new question. Please include there a MWE illustrating the undesired behaviour. – Gonzalo Medina Dec 12 '14 at 18:02
• alright, did it: tex.stackexchange.com/questions/217738/… – Adrian Pfeifle Dec 12 '14 at 18:27