I want to change the section style in my latex document, so the section text are diveded in two colors as shown in the picture. The text color should change after 3 leters from green to black. How do I do that ?enter image description here

  • What \documentclass are you using? – Werner Dec 12 '16 at 19:58
  • I'm using the article class – Morten Dec 12 '16 at 21:19
  • How would the colouring work with numbered/unnumbered sections? Can you provide an image that shows this (or are you only using \section*)? – Werner Dec 12 '16 at 21:32
  • There are no numbers. – Morten Dec 12 '16 at 21:43

Here is a solution using the titlesec package to redefine the \section* headings.


enter image description here

If you also want a horizontal line, define \section* as

\titleformat{name=\section,numberless}{\normalfont\Large\bfseries}{}{0em}{\colorthree{#1} \hrulefill}

enter image description here


The following etoolbox patch updates \@sect to colour the first three letters of all sectional titles. Spaces are gobbled, so you'll have to use ~:

enter image description here


\patchcmd{\@sect}% <cmd>
  {#8}% <search>
  {\seccolfmt #8}% <replace>
  {}{}% <success><failure>

\setcounter{secnumdepth}{0}% Don't number \section, \subsection, ...




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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