2

I provide here a MWE:

\documentclass{article}
\usepackage{titletoc}
\usepackage[colorlinks=true
 ,urlcolor=blue
 ,anchorcolor=blue
 ,citecolor=blue
 ,filecolor=blue
 ,linkcolor=blue
 ,menucolor=blue
 ,linktocpage=true
 ,bookmarks=true
 ,unicode=true
 ,pdfa=true
]{hyperref}       

\titlecontents{section}%                                        
  [9mm]                                                         
  {}                                                            
  {\contentslabel[%                                             
   \hyperlink{%
    section.\thecontentslabel
   }{%
    \thecontentslabel.%
    }]%
  {7mm}}
  {\hspace*{-7mm}}                                              
  {\hfill\contentspage}                                        
  {}                                                            

\titlecontents{subsection}%                                  
  [20mm]                                                        
  {}                                                            
  {\contentslabel[                                              
   \hyperlink{%
    subsection.\thecontentslabel%
   }{%
    \thecontentslabel%
    }]%
  {12mm}}%
  {\hspace*{-12mm}}                                            
  {\hfill\contentspage}                                         
  {}   

\begin{document}
\tableofcontents
 \section{First}
 \subsection{FF}
 \subsection{FS}
 \section{Second}
 \subsection{SF}
 \subsection{FF}
 \appendix
 \section{App1}
 \subsection{App1F}
 \subsection{App1S}
\end{document}

I have to say that the toc is exactly as I want, but there is a strange issue: while all the "1." "2." and all the subsection name are clickable and led to the correct position "A." doesn't work. How can I fix this problem possibly without any other package?

EDIT

I thought my example was minimal but after I plug it in my case it didn't work properly: I post a MWE

\documentclass{article}
\usepackage{titletoc}
\usepackage[
  colorlinks=true,
  urlcolor=blue,
  anchorcolor=blue,
  citecolor=blue,
  filecolor=blue,
  linkcolor=blue,
  menucolor=blue,
  linktocpage=true,
  bookmarks=true,
  unicode=true,
  pdfa=true,
]{hyperref}

\def\maposectionname{section}
\makeatletter
\g@addto@macro{\appendix}{%
  \titlecontents{section}%                           
   [2mm]                                                        
   {}                                                            
   {Appendix~%                                                                                    
   \hyperlink{%                                                
    section.\thecontentslabel
   }{%
    \thecontentslabel.~%
    }%
   }%
   {\hspace*{0mm}}%                                                                                         
   {\hfill\contentspage}                                                                               
  {} 
  \addtocontents{toc}{\def\protect\maposectionname{appendix}}%
}
\makeatother

\titlecontents{section}%
  [9mm]
  {}
  {\contentslabel[%
   \hyperlink{%
    \maposectionname.\thecontentslabel
   }{%
    \thecontentslabel.%
    }]%
  {7mm}}
  {\hspace*{-7mm}}
  {\hfill\contentspage}
  {}                                                            

\titlecontents{subsection}%
  [20mm]
  {}
  {\contentslabel[
   \hyperlink{%
    subsection.\thecontentslabel%
   }{%
    \thecontentslabel%
    }]%
  {12mm}}%
  {\hspace*{-12mm}}
  {\hfill\contentspage}
  {}

\begin{document}
\tableofcontents

%\clearpage
\section{First}
\subsection{FF}
\subsection{FS}

%\clearpage
\section{Second}
\subsection{SF}
\subsection{FF}

%\clearpage
\appendix
\section{App1}
\subsection{App1F}
\subsection{App1S}
\end{document}

1 Answer 1

2

This seems to work, even if the reason is puzzling. ;-)

\documentclass{article}
\usepackage{titletoc}
\usepackage[
  colorlinks=true,
  urlcolor=blue,
  anchorcolor=blue,
  citecolor=blue,
  filecolor=blue,
  linkcolor=blue,
  menucolor=blue,
  linktocpage=true,
  bookmarks=true,
  unicode=true,
  pdfa=true,
]{hyperref}

\def\maposectionname{section}
\makeatletter
\g@addto@macro{\appendix}{%
  \addtocontents{toc}{\def\protect\maposectionname{appendix}}%
}
\makeatother

\titlecontents{section}%
  [9mm]
  {}
  {\contentslabel[%
   \hyperlink{%
    \maposectionname.\thecontentslabel
   }{%
    \thecontentslabel.%
    }]%
  {7mm}}
  {\hspace*{-7mm}}
  {\hfill\contentspage}
  {}                                                            

\titlecontents{subsection}%
  [20mm]
  {}
  {\contentslabel[
   \hyperlink{%
    subsection.\thecontentslabel%
   }{%
    \thecontentslabel%
    }]%
  {12mm}}%
  {\hspace*{-12mm}}
  {\hfill\contentspage}
  {}

\begin{document}
\tableofcontents

%\clearpage
\section{First}
\subsection{FF}
\subsection{FS}

%\clearpage
\section{Second}
\subsection{SF}
\subsection{FF}

%\clearpage
\appendix
\section{App1}
\subsection{App1F}
\subsection{App1S}
\end{document}

With or without \clearpage the links should be OK.

Alternative, based on the second example.

\documentclass{article}
\usepackage{titletoc}
\usepackage[
  colorlinks=true,
  urlcolor=blue,
  anchorcolor=blue,
  citecolor=blue,
  filecolor=blue,
  linkcolor=blue,
  menucolor=blue,
  linktocpage=true,
  bookmarks=true,
  unicode=true,
  pdfa=true,
]{hyperref}

\makeatletter
\g@addto@macro{\appendix}{%
  \titlecontents{section}%
   [2mm]
   {}
   {Appendix~%
   \hyperlink{%
    appendix.\thecontentslabel
   }{%
    \thecontentslabel.~%
    }%
   }%
   {\hspace*{0mm}}%
   {\hfill\contentspage}
  {}
}
\makeatother

\titlecontents{section}%
  [9mm]
  {}
  {\contentslabel[%
   \hyperlink{%
    section.\thecontentslabel
   }{%
    \thecontentslabel.%
    }]%
  {7mm}}
  {\hspace*{-7mm}}
  {\hfill\contentspage}
  {}

\titlecontents{subsection}%
  [20mm]
  {}
  {\contentslabel[
   \hyperlink{%
    subsection.\thecontentslabel%
   }{%
    \thecontentslabel%
    }]%
  {12mm}}%
  {\hspace*{-12mm}}
  {\hfill\contentspage}
  {}

\begin{document}
\tableofcontents

\clearpage
\section{First}
\subsection{FF}
\subsection{FS}

\clearpage
\section{Second}
\subsection{SF}
\subsection{FF}

\clearpage
\appendix
\section{App1}
\subsection{App1F}
\subsection{App1S}
\end{document}
3
  • I edited my post because my MWE was not so minimal
    – MaPo
    May 11, 2016 at 15:31
  • @MaPo If you already change \titletoc for sections, there's no need for \maposecttionname.
    – egreg
    May 11, 2016 at 15:37
  • Sorry, my question was, at the end stupid. I simply should have changed section to appendix manually!
    – MaPo
    May 11, 2016 at 15:48

You must log in to answer this question.

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