我正在尝试更改 scrlttr2 中某些行的颜色,尤其是 backaddress 和主题下方的行(使用backaddress = underlined
和选项可见)。我知道我可以使用更改subject = underlined
的颜色。fromrule
\setkomafont{fromrule}{\color{red}}
当我使用时,\setkomafont{backaddress}{\color{red}}
只有地址的颜色会发生变化,但线条保持黑色。使用时\setkomafont{subject}{\color{red}}
,正如预期的那样,整个主题会变成红色,但我只希望主题下方的线条发生变化。
我还想调整线条的粗细。
这是一个 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}
非常感谢您的帮助!
答案1
据我所知,这不是预期的。因此没有可以分别通过\setkomafont
或来设置或更改的字体元素\addtokomafont
。backaddress=underline
和都subject=underline
用于\underline
元素下方的规则。我不知道如何更改此类规则的粗细。
因此,以下建议是仅能解决问题,如果您确实需要在信件中使用彩色地址和/或主题规则。
如果只更改规则的颜色,您可以重新定义\backaddr@format
和\subject@format
。两者都是内部命令,因此重新定义可能会在将来中断。此外,如果您稍后设置backaddress=plain
、或backaddress=underlined
,它们将被覆盖。subject=plain
subject=underlined
\renewcommand{\backaddr@format}[1]{\color{green}\underline{#1}}
\renewcommand{\subject@format}[1]{\color{blue}\underline{\usekomafont{subject}#1}}
例子:
\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}
结果:
如果您也想改变线条的粗细,可以使用:
\setkomavar{subject}{\setulcolor{blue}\setul{.65ex}{2pt}\ul{Here comes the subject.}}
\setkomavar{backaddress}{\setulcolor{green}\ul{Max Mustermann, Hauptstr. 1, 12345 Musterhausen}}
两个键backaddress
和都subject
必须设置为plain
。
例子:
\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}
结果: