2

I have tried to add "Appendix" in my ToC between the main work and my appendices. I also don't want any page number to be displayed for this ToC entry.

So far I have managed to bodge in an entry like this:

\documentclass[11pt,a4paper]{article}
\usepackage{tocstyle}
\usetocstyle{standard}
\settocstylefeature[-1]{pagenumberbox}{\csname @gobble\endcsname}%no page numbers for part  

\begin{document}
\tableofcontents

\section{Section in main text}
Bla bla bla...


\clearpage
\appendix
\addcontentsline{toc}{part}{Appendix}%TOC entry without page numbering 

\section{First appendix}
Bla bla bla...

\end{document}

This gives me an ToC entry that's is formatted like I want. But the hyperlink in the ToC points to the last page before the appendices.

How do I make the ToC entry so that the link points to the first page of my appendices?

Do you have any suggestions for a better/less tricky way of getting the TOC entry like i want?

3

The trick is to fake a contentsline with empty page numbers. \addcontentsline will cause the page number to be inserted, by using intermediate .aux file step.

\addtocontents{toc}{\protect\contentsline{part}{\appendixname}{}{}}

will first add the line

\@writefile{toc}{\contentsline {part}{Appendix}{}{}}

to the .aux file, the \@writefile command will then provide the correct line to the .toc finally.

Please note the \protect, since \contentsline is highly fragile.

\documentclass[11pt,a4paper]{article}
\usepackage{tocstyle}
\usetocstyle{standard}
\settocstylefeature[-1]{pagenumberbox}{\csname @gobble\endcsname}%no page numbers for part  
\usepackage{hyperref}
\begin{document}
\tableofcontents

\section{Section in main text}
Bla bla bla...


\clearpage
\appendix
\addtocontents{toc}{\protect\contentsline{part}{\appendixname}{}{}}
%\addcontentsline{toc}{part}{Appendix}%TOC entry without page numbering 

\section{First appendix}
Bla bla bla...

\end{document}

enter image description here

Edit The version with an explicit hyperlink to the appendix start (which is the same page as the first appendix section, in this case)

\documentclass[11pt,a4paper]{article}

\usepackage{tocstyle}
\usepackage{blindtext}

\usetocstyle{standard}
\settocstylefeature[-1]{pagenumberbox}{\csname @gobble\endcsname}%no page numbers for part  

\usepackage{hyperref}

\begin{document}
\tableofcontents

\section{Section in main text}
\blindtext[10]

\clearpage
\hypertarget{appendixstart}{\appendix}% Make a anchor here
\addtocontents{toc}{\protect\contentsline{part}{\protect\hyperlink{appendixstart}{\appendixname}}{}{}}

\section{First appendix}
\blindtext[10]

\end{document}

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.