下面的 latex 代码在 pdflatex 的第二轮编译时失败。如果我删除 hyperref 包,它可以编译成功,但是如果存在 hyperref 包,它就会编译失败并报错
(./master.out) (./master.out) (./master.toc) [1{/var/lib/texmf/fonts/map/pdftex /updmap/pdftex.map}] [2] (./master.lot !\contentsline 的参数有一个额外的 }。\par l.3 \contentsline {table}{\numberline {1.1}{\ignorespaces 我的表格标题...
我该如何解决它?
\documentclass[twoside,a4paper]{memoir}
\usepackage{hyperref}
\renewcommand\mempostaddchaptertotochook{%
\addchaptertoloft{lof}%
\addchaptertoloft{lot}%
}
\def\addchaptertoloft#1{%
\addtocontents{#1}{%
\protect\xcontentsline{chapter}
{\chaptername\ \thechapter\protect\nopagebreak\protect\vspace{1ex}}{}}}
\makeatletter
\def\xcontentsline#1#2#3{\@ifnextchar\contentsline
{\contentsline{#1}{#2}{#3}}{}}
\makeatother
\begin{document}
\cleardoublepage
\tableofcontents
\cleardoublepage
\listoftables
\cleardoublepage
\chapter{Chapter}
\begin{table}
\centering
\caption{My table's caption}
\begin{tabular}{l c c}
\hline
column 1 & column 2 & column 3 \\
\hline
r1 & r2 & r3 \\
r1 & r2 & r3 \\
r1 & r2 & r3 \\
r1 & r2 & r3 \\
\hline
\end{tabular}
\end{table}
\end{document}