I would like to underline section headings using different colors (e.g. red for section, yellow for subsection). So far I have only achieved to change the text color of the headings (see code), but I want to underline the headings and then change the line color while keeping the text color black.
\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[colorlinks=true]{hyperref}
\addtokomafont{section}{\color{red}}
\addtokomafont{subsection}{\color{yellow}}
\begin{document}
\section{Section}
\subsection{Subsection}
\end{document}
PS: I don't know why the code example needs \usepackage[colorlinks=true]{hyperref}
, but it doesn't compile without.
Best Answer
Update
Since KOMA-Script version 3.19 command
\sectionlinesformat
can be redefined to get the desired result using packageulem
:results in
Original answer
If you want to color only the lines you can load package
ulem
and define new commands for colored lines as suggested in its manual:Then you can add these commands to the font settings of
section
andsubsection
byWarning:
\...uline
must be the last added one to the font settings because of they take an argument. Additionally this\...uline
commands are formating commands so this is something like a misuse of the font settings.Code: