我使用这个report
课程,并且从这个网站上的其他问题中学到了东西(例如删除 LoF 中各章节图片之间的间距)如何调整 LoF 中每章图形之间的间距。我想改变传统的
\addtocontents{lof}{\protect\addvspace{10\p@}}
在 report.cls 文件中
\addtocontents{lof}{\protect\addvspace{15\p@}}
使用此补丁:
\makeatletter
\patchcmd{\@chapter}%
{\addtocontents{lof}{\protect\addvspace{10\p@}}}% <search>
{\addtocontents{lof}{\protect\addvspace{15\p@}}}% <replace>
{}{}% <success><failure>
\makeatother
但是,通过发布\tracingpatches
我可以看到以下内容:
[debug] analyzing '\@chapter'
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] ++ macro can be retokenized cleanly
[debug] -- search pattern not found in replacement text
我做错了什么吗?我不明白为什么\patchcmd
找不到指定的代码。顺便说一下,我的文档中还有其他 3 个补丁(未修改\@chapter
),它们都运行良好。
编辑:在准备 MWE 时,我意识到该包hyperref
是罪魁祸首,因为删除它可以解决问题。
\documentclass[12pt,twoside,openright]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{etoolbox}
\usepackage[pdftex,colorlinks,linkcolor=blue,citecolor=red]{hyperref}
%----------------------- Patch -----------------------
\tracingpatches
\makeatletter
\patchcmd{\@chapter}%
{\addtocontents{lof}{\protect\addvspace{10\p@}}}% <search>
{\addtocontents{lof}{\protect\addvspace{15\p@}}}% <replace>
{}{}% <success><failure>
\makeatother
%-----------------------------------------------------
\begin{document}
\listoffigures
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\appendix
\chapter{A chapter}
\addtocontents{lof}{\protect\addvspace{10pt}}%
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\end{document}
有办法修复这个问题吗?我需要继续加载hyperref
包。
答案1
hyperref
必须定义大量内部命令来完成其工作。
在这种情况下,的原始定义\@chapter
被保存到\Hy@org@chapter
,hyperref
然后\@chapter
被重新定义以进行一些链接,然后调用\Hy@org@chapter
。
所以这里的解决方案是修补\Hy@org@chapter
而不是加载\@chapter
时。hyperref
\documentclass[12pt,twoside,openright]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{etoolbox}
\usepackage[pdftex,colorlinks,linkcolor=blue,citecolor=red]{hyperref}
%----------------------- Patch -----------------------
\tracingpatches
\makeatletter
\patchcmd{\Hy@org@chapter}%
{\addtocontents{lof}{\protect\addvspace{10\p@}}}% <search>
{\addtocontents{lof}{\protect\addvspace{15\p@}}}% <replace>
{}{}% <success><failure>
\makeatother
%-----------------------------------------------------
\begin{document}
\listoffigures
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\appendix
\chapter{A chapter}
\addtocontents{lof}{\protect\addvspace{10pt}}%
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\end{document}
给出
和
[debug] tracing \patchcmd on input line 16
[debug] analyzing '\Hy@org@chapter'
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] ++ macro can be retokenized cleanly
[debug] ++ search pattern found in replacement text
[debug] ++ patching possible
[debug] == retokenizing macro now
或者,你可以尝试将补丁放入前 hyperref
应用其重新定义。
\documentclass[12pt,twoside,openright]{report}
\usepackage{etoolbox}
%----------------------- Patch -----------------------
\tracingpatches
\makeatletter
\patchcmd{\@chapter}%
{\addtocontents{lof}{\protect\addvspace{10\p@}}}% <search>
{\addtocontents{lof}{\protect\addvspace{15\p@}}}% <replace>
{}{}% <success><failure>
\makeatother
%-----------------------------------------------------
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage[pdftex,colorlinks,linkcolor=blue,citecolor=red]{hyperref}
\begin{document}
\listoffigures
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\appendix
\chapter{A chapter}
\addtocontents{lof}{\protect\addvspace{10pt}}%
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\end{document}