我正在尝试使用 memoir 类和包生成文档。不幸的是,当我尝试使用带有 的包选项hyperref
时,我遇到了很多错误。linktocpage
hyperref
\renewcommand{\cftchapterpagefont}{\textrm}
我猜解决办法应该是这个答案遇到过类似的问题,但我还没能解决。这是一个最小的工作示例:
\documentclass[openany,oneside,11pt]{memoir}
\NeedsTeXFormat{LaTeX2e}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Turkish character and language support
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[turkish,shorthands=:!]{babel}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Required packages
\RequirePackage{amssymb,amsmath,hyperref,multicol,ifthen,graphicx,pifont,rotating,xcolor}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The TOC
\cftsetindents{part}{0em}{3.0em}% Indendation and numwidth for part titles in the TOC
\cftsetindents{chapter}{1em}{2.0em}% Indendation and numwidth for chapter titles in the TOC
\setlength{\cftbeforechapterskip}{0pt}% No gap between chapter titles in the TOC
\renewcommand{\cftchapterfont}{\textrm}% Chapter title font in the TOC
\renewcommand{\cftchapterpagefont}{\textrm}% Clashes with the "linktocpage" option of the hyperref package
\renewcommand{\cftpartafterpnum}{\par % Thanks to https://tex.stackexchange.com/a/42500
\vspace{-2\baselineskip} \hskip -\memRTLleftskip\protect\mbox{}\protect\hrulefill\par%
\vspace{0.5\baselineskip} \hskip -\memRTLleftskip\protect\mbox{}\protect\hrulefill\par}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% hyperref setup
\hypersetup{%
unicode={true}, %
bookmarks={true}, %
colorlinks={true}, %
allcolors={kmavi},%
linktocpage={true}, % In TOC, links and colors for page numbers only.
pdfdisplaydoctitle={true}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The colors
\definecolor{kmavi}{RGB}{0,80,117}
\definecolor{mavi}{RGB}{0,115,168}
\begin{document}
\currentpdfbookmark{Table of Contents}{name}
\tableofcontents*
\part{My First Part}
\chapter{My First Chapter}
\chapter{My Second Chapter}
\end{document}
答案1
由于hyperref
使用page
数字作为链接锚点,\renewcommand{cftchapterpagefont}{\textrm}
将会由于期待参数而失败。
使用
\renewcommand{\cftchapterpagefont}{\rmfamily}
相反,这是一个不需要参数的字体切换。
\documentclass[openany,oneside,11pt]{memoir}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Turkish character and language support
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[turkish,shorthands=:!]{babel}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Required packages
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{ifthen}
\usepackage{graphicx}
\usepackage{pifont}
\usepackage{rotating}
\usepackage{xcolor}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The TOC
\cftsetindents{part}{0em}{3.0em}% Indendation and numwidth for part titles in the TOC
\cftsetindents{chapter}{1em}{2.0em}% Indendation and numwidth for chapter titles in the TOC
\setlength{\cftbeforechapterskip}{0pt}% No gap between chapter titles in the TOC
\renewcommand{\cftchapterfont}{\rmfamily}% Chapter title font in the TOC
\renewcommand{\cftchapterpagefont}{\rmfamily}% Clashes with the "linktocpage" option of the hyperref package
\renewcommand{\cftpartafterpnum}{\par % Thanks to https://tex.stackexchange.com/a/42500
\vspace{-2\baselineskip} \hskip -\memRTLleftskip\protect\mbox{}\protect\hrulefill\par%
\vspace{0.5\baselineskip} \hskip -\memRTLleftskip\protect\mbox{}\protect\hrulefill\par}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% hyperref setup
\hypersetup{%
unicode={true}, %
bookmarks={true}, %
colorlinks={true}, %
allcolors={kmavi},%
linktocpage={true}, % In TOC, links and colors for page numbers only.
pdfdisplaydoctitle={true}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The colors
\definecolor{kmavi}{RGB}{0,80,117}
\definecolor{mavi}{RGB}{0,115,168}
\begin{document}
\currentpdfbookmark{Table of Contents}{name}
\tableofcontents*
\part{My First Part}
\chapter{My First Chapter}
\chapter{My Second Chapter}
\end{document}