0

How can I make the hyperlinks be limited to the actual text in this table of contents while preserving the look? (I realize that this result is an obvious result of the method that I've used to make the entries become multiline, but I don't know another way to achieve the look.)

Output

\documentclass[a5paper, oneside, 11pt]{memoir}
\usepackage{hyperref}
\usepackage{bookmark}
\usepackage{fmtcount}

% Part \cftpagenumbersoff{part} \renewcommand\cftpartfont{\par\centering} \renewcommand{\thepart}{\arabic{part}} \renewcommand\partnumberline[1]{{\Ordinalstringnum{#1}}~\partname\par} \renewcommand\cftpartfont{\par\bfseries\centering} \setlength{\cftbeforepartskip}{-.5\baselineskip plus 12pt minus 3pt}% Compensate for adding a \par in \cftpartfont \makeatletter \patchcmd\l@part{% \cftpartfont {#1}% }{% \cftpartfont {#1}\par% }{\typeout{l@part patched}}{\typeout{l@part patch failed}} \makeatother \renewcommand\cftpartafterpnum{\vspace{0\baselineskip}}% Compensate for strange skip following part entries

% Chapter \renewcommand{\cftchapterfont}{\par\centering} \renewcommand{\chapternumberline}[1]{{\itshape{\Ordinalstringnum{#1}~\chaptername}}\par} \renewcommand{\cftchapterfillnum}[1]{\space---\space#1\par} \setlength{\cftbeforechapterskip}{-.5\baselineskip plus 12pt minus 3pt}% Compensate for adding a \par in \cftchapterfont \makeatletter \patchcmd\l@chapapp{% {\cftchapterfont {#1}}% }{% \par\cftchapterfont {#1}% }{\typeout{l@part patched}}{\typeout{l@part patch failed}} \makeatother \begin{document} \frontmatter \tableofcontents \chapter{Introduction} \chapter{Preface}

\mainmatter \part{The Beginning} \chapter{Where It All Began} \chapter{Some More Beginning}

\part{The Unbelievably Excrutiatingly Frustratingly Long Middle} \chapter{And It Just Keeps Going and Going and Going and Going and Going}

\part{The End} \chapter{Starting To Wrap Up} \chapter{The Insightful Conclusion}

\backmatter \bookmarksetup{startatroot} \chapter{Some Notes} \end{document}

This is a follow-up question to Memoir: Centered two-line parts with ordinal part numbers in toc where I've used the answer together with the answer to How to center-align and adjust font of the index reference in a TOC using memoir? and also some minor changes of my own.

Fredrik P
  • 1,386
  • Switch it to colorlinks (hyperref option). There is not much we can do about it. Hyperref injects something like hyperlinkstart and hyperlink end at either end of the TOC entry and since you have a design with line breaks/new paragraphs, this is what happens. – daleif Aug 09 '23 at 12:22
  • @daleif Alright. Thanks! I normally don't show the links at all. Here I showed them just to make the issue clear – Fredrik P Aug 09 '23 at 12:30
  • @daleif But I just realized that I have seen similar layouts where the links are constrained to the text, see e.g. the table of contents at the beginning of https://github.com/rrthomas/hpmor/releases/download/v1.2.5/hpmor.pdf which uses memoir and this code https://github.com/rrthomas/hpmor/blob/main/layout/hp-contents.tex. However, there the \frontmatter chapters are not included in the table of contents -- perhaps that method doesn't work for them...? – Fredrik P Aug 09 '23 at 12:37
  • They remove the pdf-border. Not sure how they make the hover effect. – daleif Aug 09 '23 at 12:53
  • @daleif The hover effect is just you viewing the pdf in Firefox :-) But here is a picture of said TOC where I show the pdf borders – Fredrik P Aug 09 '23 at 12:58
  • I don't see anything in the code. And cannot compile the manuscript. – daleif Aug 09 '23 at 13:01
  • @daleif I guess you're right. This was my attempt at implementing that code into the example in this question: page 1, page 2. The pdf borders are nowhere near as clean there. – Fredrik P Aug 09 '23 at 13:07
  • you must add links to the lines individually, you can't rely on automatic line breaking. – Ulrike Fischer Aug 09 '23 at 16:25

0 Answers0