我有一个包含一些长标题的文档。我习惯\\
在这些标题中创建换行符,以便让它们按照我的两列目录排列。问题是,当我hyperref
在文档文本中使用 创建指向那些长标题的标题的链接时,我最终得到的链接带有换行符。
如何创建带有换行符的标题超链接,而不让这些超链接出现相同的换行符?
谢谢。
% PREAMBLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[oneside,centered,twocolumn]{book}
%\usepackage[T1]{fontenc}
\special{papersize=215.9mm,279.4mm}
\usepackage[english]{babel}
\usepackage[expand]{gettitlestring}
\usepackage[sc]{mathpazo}
\linespread{1.05} % Palladio needs more leading (space between lines)
\usepackage{tocloft} % Customization of TOC LOF LOT
\makeatletter\@addtoreset{chapter}{part}\makeatother%
\usepackage[toc,page]{appendix}
\usepackage[table]{xcolor} % For links' color
\usepackage{colortbl} % To define colors
\usepackage{multirow}
\usepackage{eso-pic}
\usepackage{epigraph}
\usepackage{caption} % To change the way captions are labelled
\usepackage{pdfpages}
\usepackage{ltablex}
\usepackage{nicefrac} % to write fractions
\usepackage{attrib} % For source of quotations
\usepackage{lettrine} % For NewThought formatting
\usepackage{array} % To define width of columns in long table
\usepackage{booktabs} % Nicer spacing in columns
\usepackage{siunitx} % To write Celsius, etc.
\usepackage{enumitem} % To create item lists
\usepackage[rightmargin=0pt]{quoting}
\usepackage{scrextend}
\usepackage{threeparttable} % For table notes + To allow footnote material to stay with the tabular environment
\usepackage{relsize,etoolbox} % To make table footnote font smaller and quotes small
\usepackage{threeparttablex}
\appto\TPTnoteSettings{\footnotesize}
\usepackage{textcomp} % For Numero symbol
\usepackage{titlesec}
\usepackage[linguistics,edges]{forest}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titling}
\usepackage{fancyhdr}
\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella} % Palatino clone
\usepackage{hyperref} % Hyperlinks
\usepackage{bookmark}
\GetTitleStringDisableCommands{\def\\{}}
\begin{document}
\frontmatter
\tableofcontents
\part{Fish}
\chapter{Lyrics}
\chapter{Lyrics}
\section[Fortification and \texorpdfstring{\\}{}Exaltation and Mumification]{Fortification and Exaltation and Mumification}\label{sec:Mumification}
\section[Germination and Photography and Extraction]{Germination, Photography, and \texorpdfstring{\\}{}Extraction}\label{sec:Germination}
This is a sentence (see \nameref{sec:Mumification}) linking to a heading with a line-break in it.
This is another sentence (see \nameref{sec:Germination}) linking to a heading without line-break in it.
\end{document}
答案1
我的评论是错误的,\texorpdfstring 在这里不相关(除了帮助避免警告)。标题被传递\nameref
,\GetTitleString
因此您必须将换行符添加到要禁用的命令列表中。请注意,这意味着必须扩展标题,并且易碎的材料可能会断裂。
\documentclass[oneside,centered,twocolumn]{book}
\usepackage[expand]{gettitlestring} % use expand method
\usepackage{titlesec,etoolbox}
\makeatletter
\patchcmd\ttl@straight@i
{\def\@currentlabelname{#2}}
{\GetTitleString{#2}\let\@currentlabelname\GetTitleStringResult}
{}
{\fail}
\makeatother
\usepackage{hyperref} % Hyperlinks
\usepackage{bookmark}
\GetTitleStringDisableCommands{\def\\{}}
\begin{document}
\frontmatter
\tableofcontents
\part{Fish}
\chapter{Lyrics}
\section[Fortification and \texorpdfstring{\\}{}Exaltation and Mumification]{Fortification and Exaltation and Mumification}\label{sec:Mumification}
\section[Germination and Photography and Extraction]{Germination, Photography, and \texorpdfstring{\\}{}Extraction}\label{sec:Germination}
This is a sentence (see \nameref{sec:Mumification}) linking to a heading with a line-break in it.
This is another sentence (see \nameref{sec:Germination}) linking to a heading without line-break in it.
\end{document}