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:
- Change the color of section titles to include whole word in Awesome CV
- Changing AwesomeCV section highlighting to highlight whole first word
- All section titles in one uniform color in friggeri Latex CV
- Explanation for a latex def
- How does this partial-string color highlighting work?
- Variable color for section titles
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
%%

.clsfile 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