![在每页的右边/左边写上页数](https://linux22.com/image/463273/%E5%9C%A8%E6%AF%8F%E9%A1%B5%E7%9A%84%E5%8F%B3%E8%BE%B9%2F%E5%B7%A6%E8%BE%B9%E5%86%99%E4%B8%8A%E9%A1%B5%E6%95%B0.png)
答案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 发行版的一部分。