如何防止 hyperref 改变“部分”部分的目录页码字体?

如何防止 hyperref 改变“部分”部分的目录页码字体?

在我的 thesis.cls 中,我定义了我想要的部分部分的样式,如下所示:(如果我没记错的话,我的方法是基于如何更改 .cls 文件中 \part 的格式?

\patchcmd{\@part}% <cmd>
  {\markboth{}{}}% <search>
  {\partmark{#1}}% <replace>
  {}{}% <success><failure>
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
    \refstepcounter{part}
    \addcontentsline{toc}{part}{\normalsize\bfseries\sffamily Part \thepart\hspace{1em}\normalsize\bfseries\sffamily#1}% 
\else
  \addcontentsline{toc}{part}{\normalsize\bfseries\sffamily#1}%
\fi
\markboth{}{}% <------- the patch changed this into \partmark{#1}
{\centering
 \interlinepenalty \@M
 %\normalfont
 \ifnum \c@secnumdepth >-2\relax
   \fontsize{38pt}{72}\chaptercolor\bfseries\sffamily\partname\nobreakspace\thepart
   \par
   \vskip 20\p@
 \fi
 \fontsize{38pt}{72}\chaptercolor\bfseries\sffamily#2\par}%
\@endpart}

在我的 thesis.tex 主体中使用 \part{First part of thesis},这将给我所需的 TOC 样式,如下所示: 在此处输入图片描述

在我的 thesis.tex 文件中,我将此代码添加到序言中以启用超链接:

 \usepackage{hyperref}
    \hypersetup{
        hidelinks =true,
        colorlinks   = false
    }

每当包含 hyperref 包时,只有我的目录中的部分部分的页码字体会发生变化,如下所示:

在此处输入图片描述

其他 TOC 字体样式均未发生改变。

有什么方法可以防止 hyperref 的包含改变我的部分页码字体?

下面是一个 mwe.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mythesis}[]

\RequirePackage{calc}

\RequirePackage{etoolbox}

\newif\ifmydraft\mydraftfalse
\DeclareOption{mydraft}{\mydrafttrue}


\newcommand\docsize{}  % to allow 10pt or 11pt to be specified as option
\DeclareOption{12pt}{\renewcommand\docsize{12pt}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
\ExecuteOptions{12pt}         % define 12pt as the default doc size
\ProcessOptions\relax
\LoadClass[\docsize]{report}  % load report.cls

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PAGE LAYOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength\voffset{-1.0in}
\setlength\hoffset{-1.0in}

\setlength\topmargin{20.0mm-4.0mm}
\setlength\headheight{5.00mm}
\setlength\headsep{7.00mm}

\setlength\footskip{10.00mm}
\setlength\textheight{\paperheight
                   -\topmargin-\headheight-\headsep
                   -\footskip-15.0mm-\topmargin}

% SIDE MARGINS:
\marginparsep 1mm
\if@twoside
   \setlength\oddsidemargin{3.5cm}
   \setlength\evensidemargin{2.5cm}
   \setlength\marginparwidth{1.5cm}
\ifmydraft
    % Make room for marginal notes
    \setlength\oddsidemargin{3.5cm}
    \setlength\evensidemargin{3.5cm}
    \setlength\marginparwidth{2.25cm}
\fi
\else
   \setlength\oddsidemargin{3.5cm}
   \setlength\evensidemargin{3.5cm}
   \setlength\marginparwidth{2.25cm}
\fi

 \setlength\textwidth{\paperwidth-\oddsidemargin-\evensidemargin}

% Line spacing and par seps.
\renewcommand{\baselinestretch}{1.33333}
\newcommand\setmyparsep{\parskip0.4\baselineskip\@plus0ex\@minus 0.5ex}
\newcommand\setmytightparsep{\parskip0.2\baselineskip\@minus0.5ex}
\setlength\parindent{0ex}
\widowpenalty 10000    % completely discourage widow lines
\clubpenalty 10000     % completely discourage club (orphan) lines
\brokenpenalty 10000   % completely discourage hyphenation across pages

\if@twoside
   \flushbottom
\else
   \raggedbottom
\fi
\if@twocolumn
  \twocolumn
  \sloppy
  \flushbottom
\else
  \onecolumn
\fi

%% Modified appearance of Parts to fitthe thesis style------

\patchcmd{\@part}% <cmd>
  {\markboth{}{}}% <search>
  {\partmark{#1}}% <replace>
  {}{}% <success><failure>

\def\@part[#1]#2{%
     \ifnum \c@secnumdepth >-2\relax 
         \refstepcounter{part}%  
         \addcontentsline{toc}{part}{\normalsize\bfseries\sffamily     Part\thepart\hspace{1em}\normalsize\bfseries\sffamily#1}% 
     \else
          \addcontentsline{toc}{part}{\normalsize\bfseries\sffamily#1}%
     \fi
    \markboth{}{}% <------- the patch changed this into \partmark{#1}
    {\centering
         \interlinepenalty \@M
         %\normalfont
        \ifnum \c@secnumdepth >-2\relax
            \fontsize{38pt}{72}\bfseries\sffamily\partname\nobreakspace\thepart
            \par
             \vskip 20\p@
        \fi
     \fontsize{38pt}{72}\bfseries\sffamily#2\par}%
    \@endpart}
    %% end parts modification---------------------

下面是 thesis.tex 的一个 mwe:

\PassOptionsToPackage{usenames,dvipsnames}{xcolor}
\documentclass[a4paper,twoside,openright,12pt,mycolours,final]{mwe}

\usepackage{lmodern}

%Disable hyperref from here...
\usepackage{hyperref}
   \hypersetup{
   hidelinks =true,
   colorlinks   = false,    % Colours links instead of ugly boxes
   urlcolor     = black,    % Colour for external hyperlinks
   %linkcolor    = black,    % Colour of internal links
   citecolor    = NavyBlue %darkraspberry      % Colour of citations
   }

 % %FIX FOR BROKEN HYPERREF ON TEXLIVE2016
 \makeatletter
 \let\xx@thm\@thm
 \AtBeginDocument{\let\@thm\xx@thm}
 \makeatother
 %-----Disable hyperref from above comment and here.

\usepackage{lmodern}


\begin{document}
\tableofcontents
\part{First part of thesis}
\label{part1}

\part{Second part of thesis}
\label{part2}

\end{document}

我在运行 12.12.6 的 Mac 上使用 texlive 2017。我在终端中用来构建 tex 文件的命令是:

latexmk -pdf thesis.tex

您可以通过注释/取消注释来启用/禁用超链接设置,从而观察目录页码的差异。

相关内容