使用載入的超引用重新定義內容行

使用載入的超引用重新定義內容行

下面的 Latex 程式碼在 pdflatex 的第二輪中無法編譯。如果我刪除 hyperref 包,它可以正常編譯,但是如果它存在,它就無法編譯並抱怨給出此錯誤

(./master.out) (./master.out) (./master.toc) [1{/var/lib/texmf/fonts/map/pdftex /updmap/pdftex.map}] [2] (./ master.lot ! \contentsline 的參數有一個額外的}。

我該如何解決呢?

\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}

相關內容