Update
Since KOMA-Script version 3.19 command \sectionlinesformat
can be redefined to get the desired result using package ulem
:
\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage[normalem]{ulem}
\usepackage{blindtext}
\makeatletter
\renewcommand{\sectionlinesformat}[4]{%
\ifstr{#1}{section}
{\colorlet{ulinecolor}{red}}
{\ifstr{#1}{subsection}{\colorlet{ulinecolor}{green}}
{\colorlet{ulinecolor}{.}}}%
\@hangfrom{\hskip #2\expandafter\sectionuline\expandafter{#3}}{\expandafter\sectionuline\expandafter{#4}}%
}
\makeatother
\newcommand\sectionuline{%
\bgroup\markoverwith{\textcolor{ulinecolor}{\rule[-0.75ex]{2pt}{0.4pt}}}%
\ULon%
}
\colorlet{ulinecolor}{black}
\addtokomafont{section}{\Huge}
\begin{document}
\section{Really long section title that needs more than one line}
\subsection{Subsection}
\subsubsection{Subsubsection}
\end{document}
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:
\newcommand\sectionuline{%
\bgroup\markoverwith{\textcolor{red}{\rule[-0.5ex]{2pt}{0.4pt}}}%
\ULon%
}
\newcommand\subsectionuline{%
\bgroup\markoverwith{\textcolor{blue}{\rule[-0.5ex]{2pt}{0.4pt}}}%
\ULon%
}
Then you can add these commands to the font settings of section
and subsection
by
\addtokomafont{section}{\sectionuline}
\addtokomafont{subsection}{\subsectionuline}
Warning: \...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:
\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{ulem}
\newcommand\sectionuline{%
\bgroup\markoverwith{\textcolor{red}{\rule[-0.5ex]{2pt}{0.4pt}}}%
\ULon%
}
\newcommand\subsectionuline{%
\bgroup\markoverwith{\textcolor{blue}{\rule[-0.5ex]{2pt}{0.4pt}}}%
\ULon%
}
\addtokomafont{section}{\sectionuline}
\addtokomafont{subsection}{\subsectionuline}
\begin{document}
\section{Section}
\subsection{Subsection}
\end{document}
\usepackage{xcolor}
. You can replace\usepackage[colorlinks=true]{hyperref}
by it.hyperref
. I just said that in fact what he needs isxcolor
(also loaded byhyperref
as you said).