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

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

  • A very clean and simple solution, that's exactly what I was looking for, thank you! It also works with bookmark package. – Taekwondavide Dec 26 '18 at 23:40
  • 1
    @Taekwondavide You're welcome! – user36296 Dec 26 '18 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

  • 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). – Taekwondavide Dec 26 '18 at 23:52
  • @Taekwondavide Have you contacted the appendix package maintainer about this? – Peter Wilson Dec 27 '18 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. – Taekwondavide Dec 28 '18 at 2:52

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.