我想使用 在我的部分页面上添加题词epigraph
,但由于我也使用fancyhdr
,因此我无法使用包文档中给出的解决方案在部分页面上获得正确的页面样式。
因为我使用了report
类,所以我想到\@part
使用包来修补命令xpatch
。我所要做的就是\insertepigraph
在前面插入一个命令\@endpart
(使用几个\vfill
和\vskip
来保持页面样式合理)。一个名为\partepigraph
重新定义命令的命令包含\epigraph
命令,该命令在之后立即被清除,\clearpartepigraph
因此该命令仅影响页面的一部分。
这种方法在手动编辑 report.cls 时非常有效,但使用该命令却\xpatchcmd
没有效果,而且我不明白我的代码出了什么问题(这是我第一次使用这个命令)。
有人可以帮我修复我的代码吗?
以下是 MWE:
\documentclass[a4paper,twoside,10pt]{report}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{epigraph}
\usepackage{fancyhdr}
\usepackage{xpatch}
\usepackage{etoolbox}
\usepackage{hyperref}
\fancypagestyle{plain}{
\fancyhead{}
\fancyfoot[C]{}
\fancyfoot[LE,RO]{{\hypersetup{linkcolor=black}\hyperlink{toc}{\thepage}}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}}
\newcommand\insertepigraph{} % Insert an epigraph at the bottom of a part page
\newcommand\clearpartepigraph{\renewcommand\insertepigraph{}} % Clear the part epigraph
\newcommand\partepigraph[2]{\renewcommand{\insertepigraph}{\epigraph{#1}{#2}}} % Define the part epigraph
\tracingpatches
\makeatletter
\xpatchcmd{\@part}
{\@endpart}%
{\vfill\insertepigraph\clearpartepigraph\@endpart}%
{\PackageWarning{Patch}{Success}}
{\PackageWarning{Patch}{Failure}}
\xpatchcmd{\@part}
{\markboth{}{}}%
{\markboth{}{}\vskip 0.25\textheight}%
{\PackageWarning{Patch}{Success}}
{\PackageWarning{Patch}{Failure}}
\makeatother
\begin{document}
\thispagestyle{plain}
\partepigraph{\footnotesize La notion de passoire est indépendante de la notion de trou, et réciproquement.\\ \vskip3mm The notion of a colander is independant of the notion of a hole, and reciprocally.}{Rouxel (Les Shadoks)\\ \textit{{\scriptsize mocking the non-intuitive principles of quantum mechanics.}}}
\part{Some part title}
\part{Some other part title}
\part{Again some other part title}
\chapter{Ciel}
\end{document}
答案1
显然hyperref
对结构层代码进行了一些更改,使得\xpatchcmd{\@part}{...}
etc. 不再起作用。请在hyperref
使用前进行更改,即hyperref
稍后加载。
hyperref
使用各种驱动文件和一些使用\def\@part
,从而改变行为(稍微)→\@endpart
并且其他代码钩子再也无法找到。
\documentclass[a4paper,twoside,10pt]{report}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{epigraph}
\usepackage{fancyhdr}
\usepackage{xpatch}
%\tracingpatches
\makeatletter
\tracingpatches
\ifpatchable{\@part}{\addcontentsline}{\typeout{Yes}}{\typeout{Nope!}}
\xpatchcmd{\@part}
{\@endpart}%
{\vfill\insertepigraph\clearpartepigraph\@endpart}%
{\PackageWarning{Patch}{Success}}
{\PackageWarning{Patch}{Failure}}
\xpatchcmd{\@part}
{\markboth{}{}}%
{\markboth{}{}\vskip 0.25\textheight}%
{\PackageWarning{Patch}{Success}}
{\PackageWarning{Patch}{Failure}}
\makeatother
\usepackage{hyperref}
\fancypagestyle{plain}{
\fancyhead{}
\fancyfoot[C]{}
\fancyfoot[LE,RO]{{\hypersetup{linkcolor=black}\hyperlink{toc}{\thepage}}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}}
\newcommand\insertepigraph{} % Insert an epigraph at the bottom of a part page
\newcommand\clearpartepigraph{\renewcommand\insertepigraph{}} % Clear the part epigraph
\newcommand\partepigraph[2]{\renewcommand{\insertepigraph}{\epigraph{#1}{#2}}} % Define the part epigraph
\begin{document}
\thispagestyle{plain}
\partepigraph{\footnotesize La notion de passoire est indépendante de la notion de trou, et réciproquement.\\ \vskip3mm The notion of a colander is independant of the notion of a hole, and reciprocally.}{Rouxel (Les Shadoks)\\ \textit{{\scriptsize mocking the non-intuitive principles of quantum mechanics.}}}
\part{Some part title}
\part{Some other part title}
\part{Again some other part title}
\chapter{Ciel}
\end{document}
答案2
使用简单的重新定义\@endpart
:
\documentclass[a4paper,twoside,10pt]{report}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{epigraph}
\usepackage{fancyhdr}
\usepackage{hyperref}
\fancypagestyle{plain}{%
\fancyhead{}%
\fancyfoot[C]{}%
\fancyfoot[LE,RO]{{\hypersetup{linkcolor=black}\hyperlink{toc}{\thepage}}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}}
\newcommand\insertepigraph{} % Insert an epigraph at the bottom of a part page
\newcommand\clearpartepigraph{\renewcommand\insertepigraph{}} % Clear the part epigraph
\newcommand\partepigraph[2]{\renewcommand{\insertepigraph}{\epigraph{#1}{#2}}} % Define the part epigraph
\makeatletter
\def\@part[#1]#2{%
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\markboth{}{}
\vspace{0.25\textheight}%
{\centering
\interlinepenalty \@M \normalfont
\huge\bfseries \partname\nobreakspace\thepart\par
\vskip 20\p@ \Huge \bfseries #2\par}%
\@endpart}
\def\@endpart{%
\vfill\insertepigraph\clearpartepigraph\newpage
\if@twoside\if@openright\null
\thispagestyle{empty}%
\newpage\fi\fi}
\makeatother
\begin{document}
\thispagestyle{plain}
\partepigraph{\footnotesize La notion de passoire est indépendante de la notion de trou, et réciproquement.\\ \vskip3mm The notion of a colander is independant of the notion of a hole, and reciprocally.}{Rouxel (Les Shadoks)\\ \textit{{\scriptsize mocking the non-intuitive principles of quantum mechanics.}}}
\part{Some part title}
\part{Some other part title}
\part{Again some other part title}
\chapter{Ciel}
\end{document}
答案3
在尝试修补之前务必执行此操作\show\command
,以确保您知道要修补什么。如果\show\@part
在第一个之前添加\xpatchcmd
,您将在控制台(和文件中log
)获得以下输出:
> \@part=macro:
->\ifnum \Hy@secnum@part >\c@secnumdepth \phantomsection \fi \H@old@part .
l.23 \show\@part
?
这就像一个错误消息,但并不是真正的错误,因为没有前导!
。
这是什么意思?这hyperref
已经做了一些事情\@part
:它执行通常的操作\let\old@part\@part
并\def\@part{<something>\old@part}
在执行实际命令之前添加一些操作。
好的候选人是\H@old@part
,事实上,i\show\H@old@part
在提示符下输入
? i\show\H@old@part
> \H@old@part=macro:
[#1]#2->\ifnum \c@secnumdepth >-2\relax \refstepcounter {part}\addcontentsline
{toc}{part}{\thepart \hspace {1em}#1}\else \addcontentsline {toc}{part}{#1}\fi
\markboth {}{}{\centering \interlinepenalty \@M \normalfont \ifnum \c@secnumdep
th >-2\relax \huge \bfseries \partname \nobreakspace \thepart \par \vskip 20\p@
\fi \Huge \bfseries #2\par }\@endpart .
<insert> \show\H@old@part
l.23 \show\@part
?
很好!无需再寻找其他内容!停止交互式会话,返回文件并更改\@part
为\H@old@part
。
\documentclass[a4paper,twoside,10pt]{report}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{epigraph}
\usepackage{fancyhdr}
\usepackage{xpatch}
\usepackage{etoolbox}
\usepackage{hyperref}
\fancypagestyle{plain}{
\fancyhead{}
\fancyfoot[C]{}
\fancyfoot[LE,RO]{{\hypersetup{linkcolor=black}\hyperlink{toc}{\thepage}}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}}
\newcommand\insertepigraph{} % Insert an epigraph at the bottom of a part page
\newcommand\clearpartepigraph{\renewcommand\insertepigraph{}} % Clear the part epigraph
\newcommand\partepigraph[2]{\renewcommand{\insertepigraph}{\epigraph{#1}{#2}}} % Define the part epigraph
\tracingpatches
\makeatletter
\xpatchcmd{\H@old@part}
{\@endpart}%
{\vfill\insertepigraph\clearpartepigraph\@endpart}%
{\PackageWarning{Patch}{Success}}
{\PackageWarning{Patch}{Failure}}
\xpatchcmd{\H@old@part}
{\markboth{}{}}%
{\markboth{}{}\vskip 0.25\textheight}%
{\PackageWarning{Patch}{Success}}
{\PackageWarning{Patch}{Failure}}
\makeatother
\begin{document}
\thispagestyle{plain}
\partepigraph{\footnotesize La notion de passoire est indépendante de la notion de trou, et réciproquement.\\ \vskip3mm The notion of a colander is independant of the notion of a hole, and reciprocally.}{Rouxel (Les Shadoks)\\ \textit{{\scriptsize mocking the non-intuitive principles of quantum mechanics.}}}
\part{Some part title}
\part{Some other part title}
\part{Again some other part title}
\chapter{Ciel}
\end{document}
您可能希望将补丁放在个人包中;在这种情况下,原始修补可以在那里完成,前提是您在之前加载此个人包hyperref
。或者,如果您希望“独立”代码位于包加载之后,只需使用一个技巧:
\makeatletter
\@ifpackageloaded{hyperref}
{\xpatchcmd{\H@old@part}}
{\xpatchcmd{\@part}}
{\@endpart}%
{\vfill\insertepigraph\clearpartepigraph\@endpart}%
{\PackageWarning{Patch}{Success}}
{\PackageWarning{Patch}{Failure}}
\@ifpackageloaded{hyperref}
{\xpatchcmd{\H@old@part}}
{\xpatchcmd{\@part}}
{\markboth{}{}}%
{\markboth{}{}\vskip 0.25\textheight}%
{\PackageWarning{Patch}{Success}}
{\PackageWarning{Patch}{Failure}}
\makeatother