![章节标题中的 Hyperref 链接使内容大纲变得不好看(显示内部链接)](https://linux22.com/image/456140/%E7%AB%A0%E8%8A%82%E6%A0%87%E9%A2%98%E4%B8%AD%E7%9A%84%20Hyperref%20%E9%93%BE%E6%8E%A5%E4%BD%BF%E5%86%85%E5%AE%B9%E5%A4%A7%E7%BA%B2%E5%8F%98%E5%BE%97%E4%B8%8D%E5%A5%BD%E7%9C%8B%EF%BC%88%E6%98%BE%E7%A4%BA%E5%86%85%E9%83%A8%E9%93%BE%E6%8E%A5%EF%BC%89.png)
下面的代码在 pdf 查看器上显示的内容大纲中生成了以下丑陋的超链接(位于orgf65efce
左上角)。
\documentclass[11pt]{article}
\usepackage{hyperref}
\title{Testing Ugly Hyperref Output in Contents Outline}
\author{@nazzacode}
\hypersetup{
pdflang={English}}
\begin{document}
\maketitle
\section{\hyperref[orgf65efce]{LOL} -- This link prints ugly in the contents outline}\label{sec:org014cb14}
Here is a link:
\label{orgf65efce}LOL : Laughing Out Loud
\medskip
\noindent Please help me fix this problem!
\end{document}
我该如何修复此问题(最好保持原有链接)?
答案1
我最初确实误解了你的问题。
除非你打算将章节标题链接到文本。试试这个:
\documentclass[11pt]{article}
\usepackage[colorlinks=true]{hyperref}
\title{Testing Ugly Hyperref Output in Contents Outline}
\author{@nazzacode}
\hypersetup{
pdflang={English}}
\begin{document}
\maketitle
\section{\label{orgf65efce}{LOL} -- This link prints ugly in the contents outline}
Here is a link:
\hyperref[orgf65efce]{LOL} : Laughing Out Loud
\medskip
\noindent Please help me fix this problem!
\end{document}
答案2
hyperref 将代码拆分为文本和书签之间的标准命令是\texorpdfstring
:
\documentclass[11pt]{article}
\usepackage{hyperref}
\title{Testing Ugly Hyperref Output in Contents Outline}
\author{@nazzacode}
\hypersetup{
pdflang={English}}
\begin{document}
\maketitle
\section{\texorpdfstring{\hyperref[orgf65efce]{LOL}}{LOL} -- This link prints ugly in the contents outline}\label{sec:org014cb14}
Here is a link:
\label{orgf65efce}LOL : Laughing Out Loud
\medskip
\noindent Please help me fix this problem!
\end{document}