![使用 scrlayer-scrpage 从样本中重新创建标头](https://linux22.com/image/361323/%E4%BD%BF%E7%94%A8%20scrlayer-scrpage%20%E4%BB%8E%E6%A0%B7%E6%9C%AC%E4%B8%AD%E9%87%8D%E6%96%B0%E5%88%9B%E5%BB%BA%E6%A0%87%E5%A4%B4.png)
我想重新创建这本书的标题:
https://books.google.de/books?id=ybEmCgAAQBAJ&pg=PA36&hl=de&source=gbs_selected_pages&cad=3#v=onepage&q&f=false
示例图片:
因此,在偶数页上,章节号位于左上角的灰色框中。后面是章节名称。与此处的示例不同,页眉线应延伸至整个页面,即该线应延伸至内边距。
在奇数页上,该部分应显示在右上角。同样,标题线应延伸至整个页面。
我目前的尝试:
\documentclass[a4paper, twoside]{scrbook}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{xcolor}
\usepackage[markcase=noupper,headsepline]{scrlayer-scrpage}
\automark[section]{chapter}
\automark*[subsection]{}
\renewcommand\chaptermarkformat{}
\usepackage{adjustbox}
\newcommand{\Graybox}{\noindent\adjustbox{minipage=[c]{\marginparwidth}\centering,height=8pt, bgcolor=gray}}
\lehead{%
\makebox[0pt][r]{%
{\Graybox{\color{white}\textsf{\thechapter}}}\hspace*{1em}}%
\leftmark
}
\rohead{\rightmark}
\setkomafont{pagehead}{\normalfont\sffamily}
\usepackage{blindtext}% dummy text
\begin{document}
\Blinddocument
\end{document}
答案1
使用以下 MWE(基于本书作者 Herbert Voss 的代码的版本),您可以使用scrlayer-scrpage
而不是scrpage2
来获得所需的布局。
您应该查看以下一些事项:
和
\newlength\fullwidth
\setlength\fullwidth{\paperwidth}
\addtolength\fullwidth{-1in}
\addtolength\fullwidth{-\oddsidemargin}% für die Kopflinie
\fullwidth
标题行的长度计算为(右边距 + 文本宽度),其中
%\setheadwidth[\marginparsep]{textwithmarginpar} % <====================
%\KOMAoption{headwidth}{textwithmarginpar} % <==========================
\KOMAoption
是headwidth
设置。因为我们希望线到达纸张末端,我们不能使用textwithmarginpar
,所以我们必须使用
\KOMAoption{headwidth}{\fullwidth:0mm} % <===========================
并且headsepline
设置为
%\setheadsepline[\fullwidth]{0.8pt} % <================================
\KOMAoption{headsepline}{0.8pt} % <=====================================
使用以下 MWE
%
%%
%% Ein Beispiel der DANTE-Edition
%%
%% 1. Auflage
%%
%% Beispiel 05-02-13 auf Seite 134.
%%
%% Copyright (C) 2012 Herbert Voss
%%
%% It may be distributed and/or modified under the conditions
%% of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%%
%% See http://www.latex-project.org/lppl.txt for details.
%%
%%
%% ====
% Show page(s) 1,2,3
%%
%%
\documentclass[parskip=half,pagesize]{scrbook}
\pagestyle{empty}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{geometry,blindtext,xcolor}
\geometry{%
showframe, % <========================================================
paperheight=239mm, %
paperwidth=169mm, %
tmargin=5mm, % top
textwidth=124mm, %
textheight=195mm, %
rmargin=22mm, % right (outer)
heightrounded,
includeheadfoot,
headheight=5mm, %
headsep=8mm, %
foot=18mm, %
marginparsep=2mm, %
marginparwidth=18mm %
}
\makeatletter
\newcommand\s@pt{\hspace{6pt}}
\newcommand\chaptertext{K\s@pt a\s@pt p\s@pt i\s@pt t\s@pt e\s@pt l}
\DeclareRobustCommand\headingfont{\sffamily\bfseries}
\renewcommand\@makechapterhead[1]{\begingroup
\flushright
{\topskip\z@\null}
\headingfont\mdseries
\fontsize{14.4}{5.5pc minus .5pc}\selectfont
\textbf{\chaptertext}
\fontsize{36}{\f@baselineskip}\selectfont\ \thechapter\kern-2pt
\par
\fontsize{28}{24pt}\selectfont
\begin{minipage}{\linewidth}\flushright
\rule{0pt}{5pc}\normalfont\headingfont #1
\end{minipage}%
\null
\par\endgroup
\rule{0pt}{7.5pc}\par}
\setcounter{chapter}{4}
\newlength\fullwidth
\setlength\fullwidth{\paperwidth}
\addtolength\fullwidth{-1in}
\addtolength\fullwidth{-\oddsidemargin}% für die Kopflinie
%\setlength{\footheight}{51.3pt}
\usepackage[ilines]{scrlayer-scrpage} % scrlayer-scrpage scrpage2 <====
\pagestyle{scrheadings}
\clearscrheadfoot{}
%\setheadwidth[\marginparsep]{textwithmarginpar} % <====================
%\KOMAoption{headwidth}{textwithmarginpar} % <==========================
\KOMAoption{headwidth}{\fullwidth:0mm} % <===========================
\lehead[\clearscrheadfoot]{\mbox{\headingfont\smash{%
\setlength\fboxsep{0pt}\raisebox{-2pt}{\colorbox{blue!80}{\makebox[22mm]{\hfill%
\ifnum\value{chapter}>0
\textcolor{white}{\fontsize{18}{19}\selectfont\thechapter}~\fi%
\rule[-2.85pt]{2mm}{12mm}}}}}\quad\small\leftmark}}
\rohead[\clearscrheadfoot]{\small\headingfont\rightmark\quad\makebox[22mm]{}}
\lefoot[\clearscrheadfoot]{\small\headingfont\llap{\thepage~\rule[-13mm]{.6pt}{18mm}
\hspace{1mm}}}
\rofoot[\clearscrheadfoot]{\small\headingfont~
\hfill \rlap{\hspace{1mm}\rule[-13mm]{.6pt}{18mm}\ \thepage}}
%\setheadsepline[\fullwidth]{0.8pt} % <================================
\KOMAoption{headsepline}{0.8pt} % <=====================================
\renewcommand\chaptermark[1]{\markboth{#1}{}}
\renewcommand\sectionmark[1]{%
\markright{\ifnum\c@secnumdepth>\@ne \thesection\quad #1\fi}}
\makeatother
\begin{document}
\chapter{Textformatierungen}
\section{Seitenstil}\blindtext\par\blindtext\newpage
\section{baz} \blindtext[2]\par\blindtext\newpage
\section{foobar}\blindtext[2]\par\blindtext\newpage \blindtext[2]
\end{document}
你得到了想要的结果: