4

I found a lot of questions abount appendices and ToC. Many users want appendices to be grouped in an Appendix part, however some problems arise with ToC, hyperref, PDF viewer bookmarks, and so on.

There are different solutions which require extra packages, command patching and other extra code, however none of them satisfies me. I almost found an easy way to accomplish a good result, where appendices are added to bookmarks in the right way and hyperref links point to the right page. However, the number of the "Appendix" part page is wrong (it's the number of appendix A). Is there any EASY way to fix that?

This is a MWE:

\documentclass{book}

\usepackage[nottoc,notlot,notlof]{tocbibind}
\usepackage{hyperref}

\begin{document}

  \frontmatter
  \tableofcontents

  \mainmatter
  \part{First}
  \chapter{One}
  Lorem ipsum

  \part{Second}
  \chapter{Two}
  Dolor sit amet

  \appendix

  % These two commands do all the job:
  \addcontentsline{toc}{part}{Appendices}
  \part*{Appendices}

  \chapter{Uno}
  First appendix

  \chapter{Due}
  Secondo appendix

\end{document}

This is the ToC (with links pointing to the right page)

I  First      1
1  One        3

II Second     5  
2  Two        7

Appendices   11 (this should be 9)
A  Uno       11
B  Due       13

Using bookmark package instead of (in addition to) hyperref make it worse (Appendix link and ToC page will point to chapter "Two"). Switching \addcontentsline and \part* doesn't solve the problem.

EDIT: for some reasons, I do not want to use appendix package

0

2 Answers 2

4

You can provide a suitable target for the hyperlink by introducing a \phantomsection. To ensure that this link to the correct page, use if after \cleardoubelpage

\documentclass{book}

\usepackage[nottoc,notlot,notlof]{tocbibind}
\usepackage{hyperref}

\begin{document}

  \frontmatter
  \tableofcontents

  \mainmatter
  \part{First}
  \chapter{One}
  Lorem ipsum

  \part{Second}
  \chapter{Two}
  Dolor sit amet

  \appendix

  % These two commands do all the job:

\cleardoublepage
\phantomsection
\addcontentsline{toc}{part}{Appendices}
  \part*{Appendices}


  \chapter{Uno}
  First appendix

  \chapter{Due}
  Secondo appendix

\end{document}

enter image description here

2
  • A very clean and simple solution, that's exactly what I was looking for, thank you! It also works with bookmark package. Dec 26, 2018 at 23:40
  • 1
    @Taekwondavide You're welcome! Dec 26, 2018 at 23:41
3

The appendix package with option [toc]works fine:

\documentclass{book}
\usepackage{lipsum}
\usepackage[nottoc,notlot,notlof]{tocbibind}
\usepackage[toc]{appendix}
\usepackage{hyperref}

\begin{document}

  \frontmatter
  \tableofcontents

  \mainmatter
  \part{First}
  \chapter{One}
  \lipsum
  \part{Second}
  \chapter{Two}

\lipsum

  \appendix
  \appendixpage

  \chapter{Uno}
  First appendix

  \chapter{Due}
  Secondo appendix

\end{document} 

enter image description here

3
  • Thank you, I already knew this package, however for some reasons (such as the fact that it messes up TeXstudio structure tree) I prefer not to use it. Also, I was looking for a more general solution that may apply to other situations too (not only the appendix). Dec 26, 2018 at 23:52
  • @Taekwondavide Have you contacted the appendix package maintainer about this? Dec 27, 2018 at 20:23
  • @PeterWilson I badly explained myself. Appendix package works fine, but TeXstudio doesn't recognize \appendixpage as a new part of the document, which causes all appendices to be seen seen by the editor as chapters of the last \part in the main matter, which is quite annoying for me as I'm using TeXstudio's structure tree a lot (this is not the only reason I want to fix my code without additional packages). However, the bookmark tree in PDF viewer is correct and appendices are seen as a part. Dec 28, 2018 at 2:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .