答案1
下面是一个使用 KOMA-Script 包的示例scrlayer-scrpage
:
\documentclass{book}
\usepackage[automark,pagestyleset=KOMA-Script,headsepline]{scrlayer-scrpage}
\newlength{\outermarkoffset}
\setlength{\outermarkoffset}{\dimexpr 1in+\topmargin+\headheight+\headsep\relax}
\DeclareNewLayer[%
background,
oddpage,
outermargin,
addvoffset=\dimexpr \outermarkoffset+\baselineskip*\value{chapter}*2\relax,
contents={%
\raggedleft\pagemark\hspace*{1em}\par
},
]{oddpagenumber}
\DeclareNewLayer[%
background,
evenpage,
outermargin,
addvoffset=\dimexpr \outermarkoffset+\baselineskip*\value{chapter}*2\relax,
contents={%
\raggedright\hspace*{1em}\pagemark\par
},
]{evenpagenumber}
\AddLayersToPageStyle{scrheadings}{oddpagenumber,evenpagenumber}
\AddLayersToPageStyle{plain.scrheadings}{oddpagenumber,evenpagenumber}
\AddToHook{cmd/appendix/before}{%
\cleardoublepage
\addtolength{\outermarkoffset}{\dimexpr\baselineskip*\value{chapter}*2\relax}%
}
\usepackage{mwe}
\begin{document}
\tableofcontents
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\appendix
\blinddocument
\end{document}
如果你已经在使用包fancyhdr
,你可以改用scrlayer-fancyhdr
:
\documentclass{book}
\usepackage{scrlayer-fancyhdr}
\pagestyle{fancy}
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\pagemark}%
\renewcommand*{\headrulewidth}{0pt}%
}
\newlength{\outermarkoffset}
\setlength{\outermarkoffset}{\dimexpr 1in+\topmargin+\headheight+\headsep\relax}
\DeclareNewLayer[%
background,
oddpage,
outermargin,
addvoffset=\dimexpr \outermarkoffset+\baselineskip*\value{chapter}*2\relax,
contents={%
\raggedleft\pagemark\hspace*{1em}\par
},
]{oddpagenumber}
\DeclareNewLayer[%
background,
evenpage,
outermargin,
addvoffset=\dimexpr \outermarkoffset+\baselineskip*\value{chapter}*2\relax,
contents={%
\raggedright\hspace*{1em}\pagemark\par
},
]{evenpagenumber}
\AddLayersToPageStyle{@everystyle@}{oddpagenumber,evenpagenumber}
\AddToHook{cmd/appendix/before}{%
\cleardoublepage
\addtolength{\outermarkoffset}{\dimexpr\baselineskip*\value{chapter}*2\relax}%
}
\usepackage{mwe}
\begin{document}
\tableofcontents
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\appendix
\blinddocument
\end{document}
有关更多信息scrlayer-fancyhdr
请参阅该包的手册。
有关更多信息\DeclareNewLayer
,请\AddLayersToPageStyle
参阅KOMA 脚本手册。
有关 的更多信息,\AddToHook
请参阅lthooks-doc.pdf
,它是每个 LaTeX 发行版的一部分。