3

Being only a LaTeX novice I may have introduced a bit of customizing code renewing part formats and adjusting numberings which may have messed up the ability for hyper-references accuracy in heading to the correct target.

In short: despite having distinct labels on each hierarchy object duplicate names create problems in the hyperlinks between the TOC and the desired section: E.G.

Part 1

A <-> 1 -> goes to page 1 in Part 1

Part 2

A <-> 2 -> goes to page 1 in Part 1

Problematic Code - Reduced to MWE

\documentclass{report}

\makeatletter
    %=========================================================================================================================================
    % PACKAGES REQUIRED FOR CONTROLLING AND CONFIGURING TABLE OF CONTENTS AND OTHER LISTS
    %=========================================================================================================================================
    \usepackage[titles]{tocloft}
        \setcounter{secnumdepth}{6} 
        \setcounter{tocdepth}{6}
        \renewcommand{\cftchapfont}{\normalsize \scshape}
    \usepackage[titletoc,title]{appendix}
    \usepackage{etoolbox} % or xpatch

    \usepackage{chngcntr}           %http://tex.stackexchange.com/questions/28333/continuous-v-per-chapter-section-numbering-of-figures-tables-and-other-docume
        \counterwithin*{chapter}{part}  %http://tex.stackexchange.com/questions/54383/how-to-reset-chapter-and-section-counter-with-part
        \counterwithin*{section}{part}
        \counterwithin*{section}{chapter}

        \counterwithin*{figure}{part}
        \counterwithout{figure}{chapter}

        \counterwithin*{table}{part}
        \counterwithout{table}{chapter}

    %http://www.latex-community.org/forum/viewtopic.php?f=47&t=4293
    \renewcommand\part{%    
        \if@openright
        \cleardoublepage
        \else
        \clearpage
        \fi
        \thispagestyle{empty}%
        \if@twocolumn
        \onecolumn
        \@tempswatrue
        \else
        \@tempswafalse
        \fi
        \null\vfil
        \secdef\@part\@spart
    }

    %http://tex.stackexchange.com/questions/103926/part-title-in-list-of-figures-and-tables
    % initial definitions of the chapter info (name and number)
    \def\thischaptertitle{}\def\thischapternumber{}
    \newtoggle{noFigs}
    \newtoggle{noTabs}


    \apptocmd{\@part}%
    {\gdef\thisparttitle{#1}\gdef\thispartnumber{\thepart}%
        \global\toggletrue{noFigs}\global\toggletrue{noTabs}}{}{}

    % the figure environment does the job: the first time it is used after a \chapter command, 
    % it writes the information of the chapter to the LoF
    \AtBeginDocument{%
        \AtBeginEnvironment{figure}{%
            \iftoggle{noFigs}{
                \addtocontents{lof}{\protect\contentsline{part}%
                    {\protect\numberline{\thisparttitle}}{}{3.2em} }
                \global\togglefalse{noFigs}
            }{}
        }%
        \AtBeginEnvironment{table}{%
            \iftoggle{noTabs}{
                \addtocontents{lot}{\protect\contentsline{part}%
                    {\protect\numberline{\thisparttitle}}{}{} }
                \global\togglefalse{noTabs}
            }{}
        }%
    }


    %/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    % setup environment to permit the removal of page numbers while still continuing sequence when resumed and keeping hyperref happy   // 
    %/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    %http://tex.stackexchange.com/questions/112782/gobble-page-numbers
    \newcounter{nopage}
    \newenvironment{nopage}
    {\clearpage\stepcounter{nopage}%
        \renewcommand{\thepage}{NP\arabic{nopage}}%
        \thispagestyle{empty}}
    {\clearpage\addtocounter{page}{-1}}

    %_________________________________________________________________________________________________________________________________________

    \newenvironment{paper}{%
        \begin{sloppypar}
            \global\let\oldthesection\thesection
            \renewcommand{\thesection}{\@arabic\c@section}%
        }{%
        \end{sloppypar}
        \global\let\thesection\oldthesection
    }


    %=========================================================================================================================================
    % PACKAGES REQUIRED FOR HYPERLINKS AND HYPER-REFERENCES
    %=========================================================================================================================================
    \usepackage{csquotes}
    \usepackage{url}
    \usepackage[nottoc]{tocbibind}
    \usepackage{bookmark}

    %http://tex.stackexchange.com/questions/42927/converting-from-latex-to-html-using-htlatex
    \usepackage{hyperref}   %\usepackage{hyperref}
    \hypersetup{
        %bookmarks=false,         % show bookmarks bar?
        unicode=true,          % non-Latin characters in Acrobat's bookmarks
        pdftoolbar=true,        % show Acrobat's toolbar?
        pdfmenubar=true,        % show Acrobat's menu?
        pdffitwindow=true,     % window fit to page when opened
        pdfstartview={FitV},    % fits the height of the page to the window:  or fits the width of the page to the window  FitH
        pdftitle={My title},    % title
        pdfauthor={Author},     % author
        pdfsubject={Subject},   % subject of the document
        pdfcreator={Creator},   % creator of the document
        pdfproducer={Producer}, % producer of the document
        pdfkeywords={keyword1} {key2} {key3}, % list of keywords
        pdfnewwindow=true,      % links in new window
        colorlinks=true,       % false: boxed links; true: colored links
        linkcolor=black,          % color of internal links (change box color with linkbordercolor)
        citecolor=black,        % color of links to bibliography
        filecolor=black,      % color of file links
        urlcolor=black          % color of external links
    }

    \bookmarksetup{
        numbered,
        open
    }

    \usepackage[noabbrev]{cleveref}

    %_________________________________________________________________________________________________________________________________________

\makeatother

\begin{document}
    \tableofcontents    \addcontentsline{toc}{chapter}{Table of Contents}
    \listoffigures      %\addcontentsline{toc}{chapter}{List of Figures}
    \listoftables       %\addcontentsline{toc}{chapter}{List of Tables}

    \begin{sloppypar}% must be after abstract and title page

        \part{Author Introduction}
            %\setcounter{chapter}{0}
            \chapter{First}\label{P1I}
            \chapter{Second}\label{P1II}
            \chapter{Third}\label{P1III}


        \part{Paper 1}\label{First Paper}%
        %\setcounter{chapter}{1}
        \begin{paper}
            \section{Introduction}\label{pp1I}
            \section{Materials and Methods}\label{pp1M}
            \section{Results}\label{pp1R}
            \section{Discussion}\label{pp1D}
            \section{Conclusion}\label{pp1C}
            \section{References}\label{pp1B}
        \end{paper}     



        \part{Paper 2}\label{Second Paper}%
        %\setcounter{chapter}{1}
        \begin{paper}
            \section{Introduction}\label{pp2I}
            \section{Materials and Methods}\label{pp2M}
            \section{Results}\label{pp2R}
            \section{Discussion}\label{pp2D}
            \section{Conclusion}\label{pp2C}
            \section{References}\label{pp2B}
        \end{paper}


        \part{Global Discussion}
            \chapter{First}\label{PLI}
            \chapter{Second}\label{PLII}
            \chapter{Third}\label{PLIII}

    \end{sloppypar} 

\end{document}
1
  • This is the typical hypertexnames=true issue. Change to hypertexnames=false
    – user31729
    Mar 4, 2015 at 17:22

1 Answer 1

4

The problem is the way link destination names are generated by hyperref. If the counter value is used, this will lead to errors, since Chapter 1 occurs four times in this document, each time the chapter counter has a value of 1 then.

The relevant portion to change is hypertexnames=false (initial default value is true)

From the manual of hyperref:

Usually problems with duplicate destination names can be solved by an appropriate definition of \theH. If option hypertexnames is disabled, then a unique artificial number is used instead of the counter value. In case of page anchors the absolute page anchor is used. With option plainpages the page anchors use the arabic form. In both latter cases \hyperpage for index links is affected and might not work properly.

This happens, for example, when the chapter counter is reset by the \part (macro, e.g. the part counter is refstepped) as is done in the OP's example. In a 'standard' setup, the counter number is not reset, just advanced in every \part.

So either set hypertexnames=false either in \usepackage[...]{hyperref} or later on in \hypersetup. This will also omit any warnings about duplicate destination labels.

\documentclass{report}

\makeatletter
    %=========================================================================================================================================
    % PACKAGES REQUIRED FOR CONTROLLING AND CONFIGURING TABLE OF CONTENTS AND OTHER LISTS
    %=========================================================================================================================================
    \usepackage[titles]{tocloft}
        \setcounter{secnumdepth}{6} 
        \setcounter{tocdepth}{6}
        \renewcommand{\cftchapfont}{\normalsize \scshape}
    \usepackage[titletoc,title]{appendix}
    \usepackage{etoolbox} % or xpatch

    \usepackage{chngcntr}           %http://tex.stackexchange.com/questions/28333/continuous-v-per-chapter-section-numbering-of-figures-tables-and-other-docume
        \counterwithin*{chapter}{part}  %http://tex.stackexchange.com/questions/54383/how-to-reset-chapter-and-section-counter-with-part
        \counterwithin*{section}{part}
        \counterwithin*{section}{chapter}

        \counterwithin*{figure}{part}
        \counterwithout{figure}{chapter}

        \counterwithin*{table}{part}
        \counterwithout{table}{chapter}

    %http://www.latex-community.org/forum/viewtopic.php?f=47&t=4293
    \renewcommand\part{%    
        \if@openright
        \cleardoublepage
        \else
        \clearpage
        \fi
        \thispagestyle{empty}%
        \if@twocolumn
        \onecolumn
        \@tempswatrue
        \else
        \@tempswafalse
        \fi
        \null\vfil
        \secdef\@part\@spart
    }

    %http://tex.stackexchange.com/questions/103926/part-title-in-list-of-figures-and-tables
    % initial definitions of the chapter info (name and number)
    \def\thischaptertitle{}\def\thischapternumber{}
    \newtoggle{noFigs}
    \newtoggle{noTabs}


    \apptocmd{\@part}%
    {\gdef\thisparttitle{#1}\gdef\thispartnumber{\thepart}%
        \global\toggletrue{noFigs}\global\toggletrue{noTabs}}{}{}

    % the figure environment does the job: the first time it is used after a \chapter command, 
    % it writes the information of the chapter to the LoF
    \AtBeginDocument{%
        \AtBeginEnvironment{figure}{%
            \iftoggle{noFigs}{
                \addtocontents{lof}{\protect\contentsline{part}%
                    {\protect\numberline{\thisparttitle}}{}{3.2em} }
                \global\togglefalse{noFigs}
            }{}
        }%
        \AtBeginEnvironment{table}{%
            \iftoggle{noTabs}{
                \addtocontents{lot}{\protect\contentsline{part}%
                    {\protect\numberline{\thisparttitle}}{}{} }
                \global\togglefalse{noTabs}
            }{}
        }%
    }


    %/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    % setup environment to permit the removal of page numbers while still continuing sequence when resumed and keeping hyperref happy   // 
    %/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    %http://tex.stackexchange.com/questions/112782/gobble-page-numbers
    \newcounter{nopage}
    \newenvironment{nopage}
    {\clearpage\stepcounter{nopage}%
        \renewcommand{\thepage}{NP\arabic{nopage}}%
        \thispagestyle{empty}}
    {\clearpage\addtocounter{page}{-1}}

    %_________________________________________________________________________________________________________________________________________

    \newenvironment{paper}{%
        \begin{sloppypar}
            \global\let\oldthesection\thesection
            \renewcommand{\thesection}{\@arabic\c@section}%
        }{%
        \end{sloppypar}
        \global\let\thesection\oldthesection
    }


    %=========================================================================================================================================
    % PACKAGES REQUIRED FOR HYPERLINKS AND HYPER-REFERENCES
    %=========================================================================================================================================
    \usepackage{csquotes}
    \usepackage{url}
    \usepackage[nottoc]{tocbibind}
    \usepackage{bookmark}

    %http://tex.stackexchange.com/questions/42927/converting-from-latex-to-html-using-htlatex
    \usepackage{hyperref}   %\usepackage{hyperref}
    \hypersetup{
        %bookmarks=false,         % show bookmarks bar?
        unicode=true,          % non-Latin characters in Acrobat's bookmarks
        pdftoolbar=true,        % show Acrobat's toolbar?
        pdfmenubar=true,        % show Acrobat's menu?
        pdffitwindow=true,     % window fit to page when opened
        pdfstartview={FitV},    % fits the height of the page to the window:  or fits the width of the page to the window  FitH
        pdftitle={My title},    % title
        pdfauthor={Author},     % author
        pdfsubject={Subject},   % subject of the document
        pdfcreator={Creator},   % creator of the document
        pdfproducer={Producer}, % producer of the document
        pdfkeywords={keyword1} {key2} {key3}, % list of keywords
        pdfnewwindow=true,      % links in new window
        colorlinks=true,       % false: boxed links; true: colored links
        linkcolor=black,          % color of internal links (change box color with linkbordercolor)
        citecolor=black,        % color of links to bibliography
        filecolor=black,      % color of file links
        urlcolor=black,          % color of external links
        hypertexnames=false
    }

    \bookmarksetup{
        numbered,
        open
    }

    \usepackage[noabbrev]{cleveref}

    %_________________________________________________________________________________________________________________________________________

\makeatother

\begin{document}
    \tableofcontents    \addcontentsline{toc}{chapter}{Table of Contents}
    \listoffigures      %\addcontentsline{toc}{chapter}{List of Figures}
    \listoftables       %\addcontentsline{toc}{chapter}{List of Tables}

    \begin{sloppypar}% must be after abstract and title page

        \part{Author Introduction}
            %\setcounter{chapter}{0}
            \chapter{First}\label{P1I}
            \chapter{Second}\label{P1II}
            \chapter{Third}\label{P1III}


        \part{Paper 1}\label{First Paper}%
        %\setcounter{chapter}{1}
        \begin{paper}
            \section{Introduction}\label{pp1I}
            \section{Materials and Methods}\label{pp1M}
            \section{Results}\label{pp1R}
            \section{Discussion}\label{pp1D}
            \section{Conclusion}\label{pp1C}
            \section{References}\label{pp1B}
        \end{paper}     



        \part{Paper 2}\label{Second Paper}%
        %\setcounter{chapter}{1}
        \begin{paper}
            \section{Introduction}\label{pp2I}
            \section{Materials and Methods}\label{pp2M}
            \section{Results}\label{pp2R}
            \section{Discussion}\label{pp2D}
            \section{Conclusion}\label{pp2C}
            \section{References}\label{pp2B}
        \end{paper}


        \part{Global Discussion}
            \chapter{First}\label{PLI}
            \chapter{Second}\label{PLII}
            \chapter{Third}\label{PLIII}

    \end{sloppypar} 

\end{document}
1
  • I omitted a screen shot, since it does not provide anything different as the OP's original code.
    – user31729
    Mar 4, 2015 at 17:42

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.