使用 biblatex 和 titlesec 时出现错误的超链接

使用 biblatex 和 titlesec 时出现错误的超链接

我正在biblatex一起使用titlesec(是的,我知道它们不能很好地协同工作...)。当我包含 -package 时,titlesec书签hyperref链接到错误的页面。

考虑以下 MWE:

\documentclass{article}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book {A,
    author = {Doe, John},
    title = {A title},
    date = {2014},
    location = {A},
}
\end{filecontents}

\usepackage[
    style=authortitle,
    backend=biber,
]{biblatex}

\usepackage[
    bookmarks,
    bookmarksopen,
]{hyperref}

\addbibresource{\jobname.bib}

%\usepackage{titlesec} % uncomment to see the undesired behaviour

\begin{document}

\pagenumbering{Roman}

\tableofcontents
\newpage

\printbibliography[
    heading=bibintoc,
]

\newpage
\pagenumbering{arabic}

\section{My Section}
\cite{A}

\end{document}

任何帮助是极大的赞赏。

答案1

您一定要titlesec在 之前加载hyperref

添加\phantomsectionbefore\printbibliography可以解决问题。你可以使用补丁来避免指定它:

\documentclass{article}

\begin{filecontents}{\jobname.bib}
@book {A,
    author = {Doe, John},
    title = {A title},
    date = {2014},
    location = {A},
}
\end{filecontents}

\usepackage[
    style=authortitle,
    backend=biber,
]{biblatex}
\makeatletter
\pretocmd{\blx@head@bibintoc}{\phantomsection}{}{\ddt}
\makeatother

\usepackage{titlesec} % uncomment to see the undesired behaviour

\usepackage[
    bookmarks,
    bookmarksopen,
]{hyperref}

\addbibresource{\jobname.bib}

\begin{document}

\pagenumbering{Roman}

\tableofcontents
\newpage

\printbibliography[
    heading=bibintoc,
]

\newpage
\pagenumbering{arabic}

\section{My Section}
\cite{A}

\end{document}

相关内容