我正在尝试使用 KomaScript 创建双面文档。我想在新章节开始的每个页面上添加一些额外内容。我首先根据以下代码创建新的页面样式:这个帖子。我尝试修改那里给出的示例。到目前为止,我已经这样做了:
\documentclass[12pt,a4paper,ngerman, twoside]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage[left=3.8cm,right=2.2cm,top=3cm,bottom=3cm]{geometry}
\usepackage{xcolor}
\usepackage[headsepline, automark]{scrlayer-scrpage}
\clearpairofpagestyles
\renewcommand*\pagemark{{\usekomafont{pagenumber}Seite\nobreakspace\thepage}}
\automark[section]{section}
\ihead*{\headmark}
\ohead*{\pagemark}
\chead{}
\cfoot[]{}
\ofoot[]{}
\ifoot[]{}
\newpairofpagestyles{highlights}{
\chead{}
\KOMAoptions{headsepline=false}
\ohead*{\colorbox{blue!15}{%
\makebox[\dimexpr\linewidth-2\fboxsep][l]{\color{white}%
\hfill
\pagemark}
}
}
}
\begin{document}
\section{Section 1}
Some text.
\cleardoublepage
\thispagestyle{highlights}
\section{Section 2}
Some text.
\end{document}
这会产生以下样式的标题:
我想实现三件事:
创建一个自定义页面样式在给定的 MWE 中,我可以在特定页面(新部分开始的地方)激活它,其中包含颜色栏(我在下面指定)和页码
创建页眉中页码后面带有颜色渐变的颜色条(如果颜色条可以根据喜好随意向内或向外延伸出标题区域,那就太好了)
更改页面标记的文本颜色为白色,因此在颜色条前面有白色文字。
为了直观地了解我所追求的目标,我编辑了 MWE 的重要页面;这就是我想要实现的目标:
我已经尝试按照以下方式创建新的页面样式,上面的链接也建议了这种方式。但我没有足够的经验来tikz
让它发挥作用:
\usepackage{tikz}
\DeclareNewLayer[background,head,
contents={\hspace*{0cm}%
\tikz{
\fill[shade,left color=blue!0,right color=blue!20,right color=blue!70] (0,0)rectangle(20cm ,{1.4cm});
\node[rotate=0,font=\bfseries] at({\textwidth-0.9cm},{0})
{\ppagemark};
}}
]{highlights.bg}
\DeclareNewPageStyleByLayers{highlights}{highlights.bg}
此外,通过这种方法,我甚至不知道如何获得我想要的页码。
也许你们中有人以前做过这件事,或者对此事有足够深入的了解,从而能够帮助我。
答案1
不幸的是,我不太明白期望的结果是什么。但我建议为标题背景定义一个新层:
\DeclareNewLayer[
background,
head,
hoffset=0pt,
width=\paperwidth,
mode=picture,
contents={\putLL{\tikz{
\ifodd \value{page}
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
\else
\fill[shade,left color=blue!70,right color=blue!0]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
\fi
}}
}
]{highlights.bg}
然后您可以在新定义的页面样式的开头添加此层:
\newpairofpagestyles{highlights}{
\ohead{\pagemark}
\KOMAoptions{headsepline=false}
\addtokomafont{pagenumber}{\bfseries\color{white}}
}
\AddLayersAtBeginOfPageStyle{highlights}{highlights.bg}
例子:
\documentclass[12pt,ngerman, twoside]{scrartcl}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% needed with older TeX distributions
\usepackage{lmodern}
\usepackage{babel}
\usepackage[left=3.8cm,right=2.2cm,top=3cm,bottom=3cm]{geometry}
\usepackage{tikz}% loads xcolor, graphicx etc.
\usepackage[headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\renewcommand*\pagemark{{\usekomafont{pagenumber}Seite\nobreakspace\thepage}}
\automark[section]{section}
\ihead{\headmark}
\ohead*{\pagemark}
\newpairofpagestyles{highlights}{
\ohead{\pagemark}
\KOMAoptions{headsepline=false}
\addtokomafont{pagenumber}{\bfseries\color{white}}
}
\DeclareNewLayer[
background,
head,
hoffset=0pt,
width=\paperwidth,
mode=picture,
contents={\putLL{\tikz{
\ifodd \value{page}
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
\else
\fill[shade,left color=blue!70,right color=blue!0]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
\fi
}}
}
]{highlights.bg}
\AddLayersAtBeginOfPageStyle{highlights}{highlights.bg}
\usepackage{blindtext}% only for dummy text
\begin{document}
\section{Section 1}
Some text.
\cleardoublepage
\thispagestyle{highlights}
\blinddocument
\end{document}
但是,如果文档中的每个部分都应该从新的奇数页开始,那么您可以使用选项切换到类scrreprt
。open=right
因此,这里有一个额外的建议,假设 pagestylehighlights
使用与 pagestyle 相同的图层plain.scrheadings
和新图层highlight.bg
:
\documentclass[12pt,ngerman, twoside,open=right]{scrreprt}
\RedeclareSectionCommand[beforeskip=0pt,afterindent=false]{chapter}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% needed with older TeX distributions
\usepackage{lmodern}
\usepackage{babel}
\usepackage[left=3.8cm,right=2.2cm,top=3cm,bottom=3cm]{geometry}
\usepackage{tikz}% loads xcolor, graphicx etc.
\usepackage[headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\renewcommand*\pagemark{{\usekomafont{pagenumber}Seite\nobreakspace\thepage}}
\automark[chapter]{chapter}
\ihead{\headmark}
\ohead*{\pagemark}
\DeclareNewLayer[
background,
oddpage,% not on even pages in two-sided documents
head,
hoffset=0pt,
width=\paperwidth,
mode=picture,
contents={\putLL{\tikz{
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
}}
}
]{highlights.bg}
\DeclareNewPageStyleByLayers{highlights}{highlights.bg}
\ForEachLayerOfPageStyle{plain.scrheadings}{\AddLayersToPageStyle{highlights}{#1}}% <- add all plain.scrheadings layers to the new page style
\AddToLayerPageStyleOptions{highlights}{oninit=\addtokomafont{pagenumber}{\bfseries\color{white}}\KOMAoptions{headsepline=false}}
\renewcommand\chapterpagestyle{highlights}
\usepackage{blindtext}% only for dummy text
\begin{document}
\chapter{Chapter 1}
Some text.
\blinddocument
\end{document}
更新(关于下面的评论)
您可以使用选项addheight
、addhoffset
、addvoffset
、addwidth
、和来height
根据背景规则调整新定义的图层的位置和大小。hoffset
voffset
width
如果要垂直放大标题背景规则,可以使用图层定义中的选项addvoffset
和。addheight
上面第二个 MWE 的示例:
\DeclareNewLayer[
background,
oddpage,% not on even pages in two-sided documents
head,
addvoffset=2mm,% moves the layer 2mm down
addheight=4mm,% enlarges the height of the layer by 4mm
hoffset=0pt,
width=\paperwidth,
mode=picture,
contents={\putLL{\tikz{
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
}}
}
]{highlights.bg}
如果背景规则要从内文延伸到外纸边框,则不要更改hoffset
并调整width
:
\DeclareNewLayer[
background,
oddpage,% not on even pages in two-sided documents
head,
addvoffset=2mm,% moves the layer 2mm down
addheight=4mm,% enlarges the height of the layer by 4mm
%hoffset=0pt,% <- removed
width=\paperwidth-1in-\hoffset-\oddsidemargin,% <- changed
mode=picture,
contents={\putLL{\tikz{
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
}}
}
]{highlights.bg}
请注意,如果要在偶数页的双面文档中使用背景,则需要第二层。