Remove the colored section box from moderncv

Using moderncv as follows;

\documentclass{moderncv}

\moderncvtheme[black]{casual}


I'd like to remove the coloured struts/rectangles/boxes, adjacent to section headings, from the output.

Can someone please tell me how to do this? I have previously used latex only for article writing.

Write after your given two lines to change the color of the leading box to white:

\definecolor{mycolor}{rgb}{255,255,255}   % color white
\makeatletter                             % make @ a letter
\renewcommand*{\section}[1]{%
\phantomsection{}% reset the anchor for hyperrefs
\parbox[t]{\hintscolumnwidth}{\strut\raggedleft\raisebox{\baseletterheight}{\color{mycolor}\rule{\hintscolumnwidth}{0.95ex}}}%
\hspace{\separatorcolumnwidth}%
\parbox[t]{\maincolumnwidth}{\strut\sectionstyle{#1}}%
\makeatother


This workaround runs with the styles casual and classic but not with banking. I changed only the used color from \color{color1} to \color{mycolor} and set mycolor to white. The original definition of macro section you can find in the file moderncvstyleclassic.sty.

Have you checked the style banking? This style does not use colored boxes.

Update to class moderncv, version 2.0.0 (current version):

with the current class moderncv, version 2.0.0 the definition in style casual has changed to:

\RenewDocumentCommand{\section}{sm}{%
\phantomsection{}% reset the anchor for hyperrefs
\cvitem[0ex]{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}%


Therefore we need to use command \RenewDocumentCommand to redefine \color{color1} to \color{white}. Please note that a patch with command \patchcmd is not working, commands defined with \RenewDocumentCommand are not patchable!

We need to add the following code into the preamble (\makeatletter and \makeatother are needed because the code uses @):

\makeatletter
\RenewDocumentCommand{\section}{sm}{%
\phantomsection{}% reset the anchor for hyperrefs
\cvitem[0ex]{\strut\raggedleft\raisebox{\baseletterheight}{\color{white}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}%
\makeatother


With the complete code

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

\moderncvstyle{casual} % casual, classic, banking, oldstyle and fancy  % head 2, body 1, foot 1
\moderncvcolor{black}

\usepackage[utf8]{inputenc}

\usepackage[scale=0.75]{geometry}

\makeatletter
\RenewDocumentCommand{\section}{sm}{%
\phantomsection{}% reset the anchor for hyperrefs
\cvitem[0ex]{\strut\raggedleft\raisebox{\baseletterheight}{\color{white}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}%
\makeatother

% personal data
\name{John}{Doe}
\title{Resumé title}
\phone[mobile]{+1~(234)~567~890}
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}
\email{john@doe.org}
\homepage{www.johndoe.com}
\social[github]{jdoe}
\photo[64pt][0.4pt]{example-image-a}
\quote{Some quote}

\setlength{\footskip}{70pt}

\begin{document}

\makecvtitle

\section{Education}
\cventry{year--year}{Degree}{Institution--3}{City--4}{\textit{Grade}--5}{Description--6}  % arguments 3 to 6 can be left empty

\section{Master thesis}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}

\section{Experience}
\subsection{Vocational}
\cventry{year--year}{Job title}{Employer}{City}{}{General description
no longer than 1--2 lines.\newline{}%
Detailed achievements:%
\begin{itemize}%
\item Achievement 1;
\item Achievement 2, with sub-achievements:
\begin{itemize}%
\item Sub-achievement (a);
\item Sub-achievement (b), with sub-sub-achievements (don't do this!);
\begin{itemize}
\item Sub-sub-achievement i;
\item Sub-sub-achievement ii;
\item Sub-sub-achievement iii;
\end{itemize}
\item Sub-achievement (c);
\end{itemize}
\item Achievement 3.
\end{itemize}}
\cventry{year--year}{Job title}{Employer}{City}{}{Description
line 1\newline{}Description line 2}
\subsection{Miscellaneous}
\cventry{year--year}{Job title}{Employer}{City}{}{Description}

\end{document}


\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\patchcmd{\section}% <cmd>
{\strut}% <search>
{\strut\renewcommand{\raisebox}[2]{}}% <replace>
{}{}% <success><failure>


to your document preamble removes the boxes altogether by making the \raisebox command equivalent to a no-op, thereby gobbling its two arguments. This redefinition of \raisebox is local, since it is executing inside a \parbox.

The output below is obtained using the casual template (template.tex) with a black style and using the image example-image-16x10 (from the mwe package) for the \photo:

• Clever workaround! – Xavier Jun 10 '13 at 3:07
• This did not work for me, but the other answer did. Any ideas of why this does not work now? Has the moderncv package changed since this was posted? – matsr Sep 30 '13 at 18:55
• @matsr: Yes, it seems that way. I'll fix this later. – Werner Sep 30 '13 at 19:27