2

I'm using hyperref (and titletoc) package(s). I redefined \appendix that way

\newif\if@appendix\@appendixfalse
\renewcommand\appendix{\par
\setcounter{section}{0}%
\setcounter{subsection}{0}%
\gdef\thesection{\@Alph\c@section}%
\@appendixtrue
}

\@appendix if is needed to modify the heading title, as i asked before here:

\DeclareRobustCommand{\@seccntformat}[1]{%                     
 \def\temp@@a{#1}%
 \def\temp@@b{section}%
 \ifx\temp@@a\temp@@b                                          
  \if@appendix
   \csname the#1\endcsname :\quad%                              
  \else
    \csname the#1\endcsname .\quad%
  \fi
  \else                                                         
   \csname the#1\endcsname\quad%                                
  \fi
  } 

and

\renewcommand\section{\@startsection%
 {section}{0}{0mm}%
 {2\baselineskip}{0.5\baselineskip}%
 {\centering\normalfont\normalsize\scshape
 \if@appendix{%
  Appendix~%
  }\fi
}%

}

in practice if I'm writing

  subsection            ==> x.y subsection_name
  section_not_appendix  ==> x. section_name
  section_appendix      ==> Appendix x: appendix_name

for the moment I got what I wanted without using any other package which I would like possibly not to use.

My question is: Now I want to modify toc entry in the table of contents, in particular I would like to have such format

  Apppendix x: appendix_name

where x is also an hyperref linking to the appendix. I think that the easiest way to proceed (without adding any other packages) is to modify further the definition of \section in order to change the \addcontentesline command which should sit in it. Can anyone help me?

EDIT

A minimal example is the following

\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
 ,pdfcreator={XeLaTeX}
 ,pdfa=true
]{hyperref}           

\makeatletter                                                   
 \renewcommand\section{\@startsection%
  {section}{0}{0mm}%
  {2\baselineskip}{0.5\baselineskip}%
  {\centering\normalfont\normalsize\scshape
  \if@appendix{%
   Appendix~%
  }\fi
  }%
 }

 \renewcommand\subsection{\@startsection%                       
  {subsection}{1}{0mm}%
  {1\baselineskip}{0.5\baselineskip}%
  {\centering\normalfont\normalsize\itshape}%
 }

 \DeclareRobustCommand{\@seccntformat}[1]{%                     
  \def\temp@@a{#1}%
  \def\temp@@b{section}%
  \ifx\temp@@a\temp@@b                                          
   \if@appendix
    \csname the#1\endcsname :\quad%                              
   \else
    \csname the#1\endcsname .\quad%
   \fi
  \else                                                         
   \csname the#1\endcsname\quad%                             
  \fi
 } 

\makeatletter
 \renewcommand\tableofcontents{%
  \section*{\contentsname
  \@mkboth{%
   \contentsname}{\contentsname}}%
  \@starttoc{toc}%
  \addvspace{32\p@\@plus14\p@}%
  %\addcontentsline{toc}{section}{\contentsname}
 }

 \newif\if@appendix\@appendixfalse
 \renewcommand\appendix{\par
  \setcounter{section}{0}%
  \setcounter{subsection}{0}%
  \gdef\thesection{\@Alph\c@section}%
  \@appendixtrue
  }

\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
 \section{First}
 \subsection{First-first}
 \subsection{First-second}
 \section{Second}
 \section*{Unnumbered}
 \addcontentsline{toc}{section}{Unnumbered}
 \subsection{Second-First}
 \appendix
 \section{This is the app}
\end{document}

The output of the table of contents the one I want to get except for the fact that I would like to have the appendix entry almost like the unnumbered entry: I would like it to be

 Appendix A: This is the app

with the A a hyperref to the appendix. How can i do?

  • Can you provide at least some working document to work with. Is titletoc really necessary? – user31729 May 10 '16 at 11:55
  • @ChristianHupfer Thanks for the attention. I edited the question adding an example. – MaPo May 10 '16 at 14:41
1

Maybe I found a solution, it's enough to define

\renewcommand\appendix{\par
 \setcounter{section}{0}%
 \setcounter{subsection}{0}%
 \gdef\thesection{\@Alph\c@section}%
 \@appendixtrue
 \titlecontents{section}%                                        
  [2mm]                                                         
  {}                                                            
  {Appendix~%                                             
  \hyperlink{%
   section.\thecontentslabel
   }{%
  \thecontentslabel.~%
   }%
  }
 {\hspace*{-7mm}}                                              
 {\hfill\contentspage}                                         
 {} 
 }
  • You are probably receiving some "duplicate destination" warnings. Add \renewcommand{\theHsection}{appendix.\thesection} to your \appendix command. – Werner May 10 '16 at 19:23
  • @Werner I found another problem: the number of the section are no more clickable! How can I fix this? – MaPo May 11 '16 at 13:55

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.