Hyperref:更改所有連結的字體,包括腳註

Hyperref:更改所有連結的字體,包括腳註

我想將 生成的所有連結的字體更改為hyperref,例如sffamily。為此,我使用etoolbox套件來修補\Hy@colorlink命令如下:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\Hy@colorlink}{\begingroup}{\begingroup\sffamily}{}{}%
\makeatother

這適用於除腳註之外的所有類型的連結。我不知道為什麼會這樣。為了您的方便,下麵包含了一個最小的工作範例。

預先感謝您的幫忙!

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{etoolbox}

% This throws an error
%\AtBeginDocument{%
%    \makeatletter
%    \patchcmd{\Hy@colorlink}{\begingroup}{\begingroup\sffamily}{}{}%
%    \makeatother
%}

\begin{document}
\makeatletter
\patchcmd{\Hy@colorlink}{\begingroup}{\begingroup\sffamily}{}{}%
\makeatother

\tableofcontents

\section{A section}\label{sec:toto}

\begin{enumerate}
    \item Pageref: page~\pageref{sec:toto}.
    \item All links have the new font except footnotes: One\footnote{One} two\footnote{Two} three.\footnote{Three}
\end{enumerate}

\end{document}

在此輸入影像描述

答案1

建立腳註標記的標準指令包含 \normalfont 指令。如果你刪除它,它就會起作用。

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{etoolbox}
\makeatletter
 \AtBeginDocument{%
    \patchcmd{\Hy@colorlink}{\begingroup}{\begingroup\sffamily}{}{}%
    \patchcmd{\@makefnmark}{\normalfont}{\selectfont}{}{}%
}
\makeatother
\begin{document}

\tableofcontents

\section{A section}\label{sec:toto}

\begin{enumerate}
    \item Pageref: page~\pageref{sec:toto}.
    \item All links have the new font except footnotes: One\footnote{One} two\footnote{Two} three.\footnote{Three}
\end{enumerate}

\end{document}

在此輸入影像描述

相關內容