在 scrartcl 中设置 headepline 颜色

在 scrartcl 中设置 headepline 颜色

我正在努力向我的页眉中添加带有彩色标题线的页眉。

我曾尝试添加这样的命令:

\setheadsepline{\color{1blue}}

但是,我得到的不是彩色线条,而是整个文本都变成了蓝色。我知道这可能是一个更简单的解决方法,但我就是找不到。我希望标题行的颜色与标题页的颜色相同。

样本:

\documentclass[a4paper,12pt,titlepage]{scrartcl}

\usepackage[left=2.5cm, right=2cm]{geometry}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fontenc}

\usepackage{microtype} %Spacing
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}

%\usepackage{hyperref}
\usepackage{url}
\urlstyle{same}

\usepackage{caption}

\usepackage{float}

\usepackage{setspace}

%Titlepage
\colorlet{1blue}{RoyalBlue!65}

%NewCommand HRule for Titlepage
\newcommand{\HRule}{\textcolor{1blue}{\rule{\textwidth}{0.5mm}}}

%Header
\usepackage[automark, headsepline]{scrpage2}
\pagestyle{scrheadings}
\setheadsepline{\color{1blue}}
\ihead{}
\chead{}
%\ohead{\includegraphics[width=2.5cm]{Bilder/krutec-logo-m.png}}
\ifoot{}
\cfoot{}
\ofoot{\pagemark}

\begin{document}

Minimal example

\end{document}

答案1

\setheadsepline不需要颜色,但需要长度作为强制参数。因此您的示例会导致错误消息:

./test.tex:32: Argument of \@scr@setline has an extra }.
<inserted text> 
                \par 
l.32 \setheadsepline{\color{1blue}}

但是,scrpage2已过时/弃用。请参阅生成的警告消息scrpage2

Package scrpage2 Warning: usage of obsolete package!
(scrpage2)                Package `scrpage2' is obsolete.
(scrpage2)                You should not longer use package `scrpage2'.
(scrpage2)                You should replace usage of package `scrpage2'
(scrpage2)                by `scrlayer-scrpage' on input line 52.

或者查看scrpage2手册,scrpage2.pdf其标题为:

过时的软件包 scrpage2

并在第一章的序言中指出:

建议使用 scrlayer-scrpage

按照上面显示的信息推荐的方式使用scrlayer-scrpage,使用正确的用户界面设置颜色,这在 KOMA-Script 手册中有说明,scrguien.pdf或者scrguide.pdf

\documentclass[12pt,titlepage]{scrartcl}% a4paper is default

% 1st: Load packages
\usepackage[left=2.5cm, right=2cm]{geometry}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fontenc}
\usepackage{microtype} %Spacing
\usepackage{graphicx} % not used by the example
\usepackage[dvipsnames]{xcolor}
\usepackage{caption} % not used by the exmaple
\usepackage{float} % not used by the example
\usepackage{setspace}

\usepackage[automark,headsepline]{scrlayer-scrpage}% scrpage2 is obsolete
\usepackage{url}
%\usepackage{hyperref}

% 2nd: Do configuration (using the packages)

\newcommand{\HRule}{\textcolor{1blue}{\rule{\textwidth}{0.5mm}}}% not used by the example
\colorlet{1blue}{RoyalBlue!65}
\urlstyle{same} % not used by the example

\pagestyle{scrheadings}
\addtokomafont{headsepline}{\color{1blue}}% setting up the colour of element headsepline
\clearpairofpagestyles
%\ohead{\includegraphics[width=2.5cm]{Bilder/krutec-logo-m.png}}
\ofoot*{\pagemark}% \pagemark also on plain pages

\begin{document}

Minimal example

\end{document}

结果是:

页面左上边缘

答案2

您误解了以下语法\setheadsepline

\documentclass[a4paper,12pt,titlepage]{scrartcl}

\usepackage[left=2.5cm, right=2cm]{geometry}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fontenc}

\usepackage{microtype} %Spacing
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}

%\usepackage{hyperref}
\usepackage{url}
\urlstyle{same}

\usepackage{caption}

\usepackage{float}

\usepackage{setspace}

%Titlepage
\colorlet{1blue}{RoyalBlue!65}

%NewCommand HRule for Titlepage
\newcommand{\HRule}{\textcolor{1blue}{\rule{\textwidth}{0.5mm}}}

%Header
\usepackage[automark, headsepline]{scrpage2}
\pagestyle{scrheadings}
\setheadsepline{0.5mm}[\color{1blue}]
\ihead{}
\chead{}
%\ohead{\includegraphics[width=2.5cm]{Bilder/krutec-logo-m.png}}
\ifoot{}
\cfoot{}
\ofoot{\pagemark}

\begin{document}

Minimal example

\end{document}

在此处输入图片描述

相关内容