1

I am making a resume using the twenty second CV template. This colours in the first 3 letters of a section heading in the main column. I would like to extend this to colour the first word of the section heading.

As far as I can tell, the relevant bits of the .cls file start at line 238:

\newcounter{colorCounter}
\def\@sectioncolor#1#2#3{
  {%
  % Switch between blue and gray
   \round{#1#2#3}{%
      \ifodd\value{colorCounter}%
        mainblue%
      \else%
        maingray%
      \fi%
    }%
  }%
  \stepcounter{colorCounter}%
}

\renewcommand{\section}[1]{ \par% {% \LARGE \color{headercolor}% @sectioncolor #1% } \par\vspace{\parskip} }

I understand that @sectioncolor#1#2#3 takes the first three letters/tokens of the section title and colours them, and that I can extend this (at least as long as the section title) by appending #4... etc. I can also change the colour of the whole title, but haven't yet worked out how to change only the first word.

I have read a few other questions on similar topics, but they use a different CV template and I haven't been able to convert those solutions to this particular problem:

EDIT:

After Simon's answer below, I made some edits to the .cls file that rotate the colours through a list.

RequirePackage{parskip}
\RequirePackage{xstring}

%%% Counter and colour first word \newcounter{colorCounter} \makeatletter \def@sectioncolor#1{% \StrBetween[1,2]{ #1 }{ }{ }[\FirstWord] \StrBehind{#1}{\FirstWord}[\LastWords] {\color{% \ifcase\value{colorCounter}% pblue\or% red\or% orange\or% blue\or% green\or% purple\else% pblue\fi% } \FirstWord}\LastWords \stepcounter{colorCounter}% }

\renewcommand{\section}[1]{%
\par% {% \LARGE \color{headercolor}% @sectioncolor{#1}% } \par\vspace{\parskip} }
\makeatother %%

cjdbarlow
  • 13
  • 4

1 Answers1

3

Add this code between \documentclass[]{twentysecondcv} and \begin{document}

% **************************************** added <<<<<<<<<<<<<<<<
\usepackage{xstring}
\makeatletter

\def@sectioncolor#1{% \StrBetween[1,2]{ #1 }{ }{ }[\FirstWord] \StrBehind{#1}{\FirstWord}[\LastWords]
{\round{\FirstWord}{% \ifodd\value{colorCounter}% mainblue% \else% maingray% \fi% }\LastWords% }% \stepcounter{colorCounter}% }

\renewcommand{\section}[1]{%
\par% {% \LARGE \color{headercolor}% @sectioncolor{#1}% } \par\vspace{\parskip} }
\makeatother % *****************************************************

a

Simon Dispa
  • 39,141
  • Thanks, this worked brilliantly. I ended up making some changes to the .cls file and also letting it cycle between a set of colours, but couldn't have got there without you and your use of xstring. – cjdbarlow Mar 19 '22 at 21:04
  • hello! how this should change if i want that all words are highlighted? In the example, only the word "other" is in blue, how should i change it for "other information"? thanks. – federico rovere May 07 '22 at 13:10