3

I am trying to change the colors of some lines in scrlttr2, especially the lines below the backaddress and the subject (visible with the backaddress = underlined and subject = underlined options). I know I can change the color of the fromrule with \setkomafont{fromrule}{\color{red}}.

When I use \setkomafont{backaddress}{\color{red}} only the address's color changes, but the line stays black. With \setkomafont{subject}{\color{red}}, as expected, the whole subject turns red, but I only want the line below the subject to change.

And I would also like to adapt the thickness of the lines.

Here's a mwe:

\documentclass[
  fromalign = right,
  fromrule = aftername,
  backaddress = underlined,
  subject = underlined,
  subject = centered,
]{scrlttr2}

\usepackage{xcolor}  

\begin{document}

\setkomavar{fromname}{Max Mustermann}
\setkomavar{fromaddress}{Hauptstr. 1\\ 12345 Musterhausen}
\setkomavar{subject}{Here comes the subject.}

\setkomafont{fromrule}{\color{red}}
\setkomafont{fromaddress}{\color{red}\itshape}
\setkomafont{backaddress}{\color{red}}
\setkomafont{subject}{\color{red}}

\makeatletter
\@setplength{fromrulethickness}{2pt}
\@setplength{fromrulewidth}{9cm}
\makeatother

\begin{letter}{Somebody}
  \opening{To whom it may concern,}
  here comes some text
  \closing{Kind regards,}
\end{letter}

\end{document}

Thanks a lot for the help!

1 Answers1

1

AFAIK that is not intended. So there is no font element which could be set or changed by \setkomafont or \addtokomafont, respectively. Both backaddress=underline and subject=underline uses \underline for the rule below the element. I do not know how the thickness of such a rule can be changed.

So the following suggestions are only workarounds, if you really need colored backaddress and/or subject rules in a letter.


To change only the color of the rules, you can redefine \backaddr@format and \subject@format. Both are internal commands, so the redefinitions can break in the future. Additionally they will be overwritten if you set later backaddress=plain, backaddress=underlined, subject=plain or subject=underlined.

\renewcommand{\backaddr@format}[1]{\color{green}\underline{#1}}
\renewcommand{\subject@format}[1]{\color{blue}\underline{\usekomafont{subject}#1}}

Example:

\documentclass[
  fromalign = right,
  fromrule = aftername,
  %backaddress = underlined,% <- default
  subject = underlined,
  subject = centered,
]{scrlttr2}

\usepackage{xcolor}

\setkomafont{fromrule}{\color{red}}
\setkomafont{fromaddress}{\color{red}\itshape}
\setkomafont{backaddress}{\color{red}}
\setkomafont{lettersubject}{\color{red}}

\makeatletter
\@setplength{fromrulethickness}{2pt}
\@setplength{fromrulewidth}{9cm}

\renewcommand{\backaddr@format}[1]{\color{green}\underline{#1}}
\renewcommand{\subject@format}[1]{\color{blue}\underline{\usekomafont{subject}#1}}
\makeatother

\begin{document}

\setkomavar{fromname}{Max Mustermann}
\setkomavar{fromaddress}{Hauptstr. 1\\ 12345 Musterhausen}
\setkomavar{subject}{Here comes the subject.}

\begin{letter}{Somebody}
  \opening{To whom it may concern,}
  here comes some text
  \closing{Kind regards,}
\end{letter}

\end{document}

Result:

enter image description here


If you want to change the thickness of the lines too, you can use:

\setkomavar{subject}{\setulcolor{blue}\setul{.65ex}{2pt}\ul{Here comes the subject.}}
\setkomavar{backaddress}{\setulcolor{green}\ul{Max Mustermann, Hauptstr. 1, 12345 Musterhausen}}

The both keys backaddress and subject must be set to plain.

Example:

\documentclass[
  fromalign = right,
  fromrule = aftername,
  backaddress = plain,% <- plain
  %subject = plain,% <- changed, but plain is default
  subject = centered,
]{scrlttr2}

\usepackage{xcolor}
\usepackage{soul}% <- added

\setkomafont{fromrule}{\color{red}}
\setkomafont{fromaddress}{\color{red}\itshape}
\setkomafont{backaddress}{\color{red}}
\setkomafont{lettersubject}{\color{red}}

\makeatletter
\@setplength{fromrulethickness}{2pt}
\@setplength{fromrulewidth}{9cm}
\makeatother

\begin{document}

\setkomavar{fromname}{Max Mustermann}
\setkomavar{fromaddress}{Hauptstr. 1\\ 12345 Musterhausen}



 \setkomavar{subject}{\setulcolor{blue}\setul{.65ex}{2pt}\ul{Here comes the subject.}}
    \setkomavar{backaddress}{\setulcolor{green}\ul{Max Mustermann, Hauptstr. 1, 12345 Musterhausen}}

\begin{letter}{Somebody}
  \opening{To whom it may concern,}
  here comes some text
  \closing{Kind regards,}
\end{letter}

\end{document}

Result:

enter image description here

esdd
  • 85,675
  • Thank you very much! It does exactly what I was looking for. Just one little follow-up question. When I use \enquote{...} from the csquotes package within the subject, I get a runaway argument. Is that a bug in csquotes? – El Cattivo Nov 15 '18 at 15:41
  • 1
    See https://tex.stackexchange.com/q/443055/43317. – esdd Nov 15 '18 at 16:01