[Tex/LaTex] Section numbers colored

colorkoma-scriptsectioning

I want to color the section and subsection numbers in my document.

I tried the solution here https://tex.stackexchange.com/a/193186/80972 but it doesn't work for me.

Here's an example using that solution

\documentclass[]{scrartcl}

\usepackage[svgnames]{xcolor}

\renewcommand*{\othersectionlevelsformat}[3]{\textcolor{LightSteelBlue}{#3}\autodot\enskip}

\begin{document}

\section{A section}

Bla bla.

\subsection{A subsection}

Bla.

\end{document} 

enter image description here

As you can see the numbers are still black.

Any help is appreciated. Best regards.

Best Answer

The command \othersectionlevelsformat, in latest versions of KOMA-Script, doesn't work as before any more (to say the truth I think it's there for backwards compatibility only).

Now every sectioning command has its own formatting command. Here's a list:

\partformat
\chapterformat
\sectionformat
\subsectionformat
\subsubsectionformat
\paragraphformat
\subparagraphformat

So, instead of using \othersectionlevelsformat you will have to use \sectionformat and \subsectionformat in this way:

\renewcommand*{\sectionformat}{%
  \textcolor{LightSteelBlue}{\thesection}\autodot\enskip%
}
\renewcommand*{\subsectionformat}{%
  \textcolor{LightSteelBlue}{\thesubsection}\autodot\enskip%
}

MWE:

\documentclass[]{scrartcl}

\usepackage[svgnames]{xcolor}

\renewcommand*{\sectionformat}{%
  \textcolor{LightSteelBlue}{\thesection}\autodot\enskip%
}
\renewcommand*{\subsectionformat}{%
  \textcolor{LightSteelBlue}{\thesubsection}\autodot\enskip%
}

\begin{document}

\section{A section}

Bla bla.

\subsection{A subsection}

Bla.

\end{document} 

Output:

enter image description here

Related Question