1

Thanks to this question I manged to get my unnumbered sections aligned in table of contents, but as I'm using to highlight pdfborderstyle I get an outline, or highlight, that is not indented. Like this (code below),

JESUS

is there a way to indent to that the pdfborderstyle get's indented, i.e. stops at the blue line? If that makes sense.

\documentclass{book}
\usepackage{hyperref}
            \hypersetup{pdfborderstyle={/S/U/W 1} % thanks, http://tex.stackexchange.com/a/26085/22939
}
 \begin{document}
 \tableofcontents

 \chapter{Introduction}
 \chapter*{Main point}
 \phantomsection\addcontentsline{toc}{chapter}{\protect\hphantom{\numberline{\thesection}}Main point}
 \chapter{Some additional material}

 \end{document}
3

It won't work with your code (which by the way is too complicated, there is no need for \hphantom, an empty \numberline would do the same thing: \addcontentsline{toc}{chapter}{\protect\numberline{}Main point})

You will have to define a new contentline type:

\documentclass{book}
\usepackage{hyperref}
            \hypersetup{pdfborderstyle={/S/U/W 1} % thanks, http://tex.stackexchange.com/a/26085/22939
}
\makeatletter
\def\toclevel@schapter{0}
\newcommand*\l@schapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip\numberline{}%
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
\makeatother  
 \begin{document}
 \tableofcontents

 \chapter{Introduction}
 \chapter*{Main point}
 \addcontentsline{toc}{schapter}{Main point}
 \chapter{Some additional material}

 \end{document}

enter image description here

  • This is my last +1. Very good and I send you a greeting. – Sebastiano May 11 '18 at 13:24
  • Thank you for answering my question. There's still something with where it links to that is kinda strange. When I click Introduction and Some additional material from the document TOC, and from the pdf-viewer's TOC, I am sent to the top of the page, but clicking Main point, both places, send me to the middle of the page where Main point is at the top. Is it possible to anchor the \addcontentsline, or what it is, to the top of the page in the same way that Introduction and Some additional material is anchored? – Eric Fail May 11 '18 at 14:07
  • 1
    Remove the manual \phantomsection. – Ulrike Fischer May 11 '18 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.