1

I'm currently writing a document using custom chapter numbering and it has stuffed up the contents hyperlinks.

I have it so that the first few chapters are numbered using roman numerals starting at I and then the numbering restarts for another set of chapters, this time using arabic numerals.

But, when I click on the link for the first arabic numbered chapter it takes me to the first roman numbered chapter, the same for all the other numbers (i.e. 2-->II). The page number links also have the same issue.

If I manually add a chapter link to the toc then it doesn't add the number before the title in the margin, something I'd like to keep.

An example of essentially what my code is:

\documentclass[a4paper, english, 12pt]{book}
\setlength{\parindent}{0em}

\usepackage{fancyhdr}

\usepackage{fix-cm}

\usepackage[justification=centering]{caption}
\usepackage{babel}
\usepackage{subcaption}
\usepackage{placeins}

\usepackage{amsmath}
    \numberwithin{equation}{chapter}
    \setlength{\jot}{2em}
\usepackage{nccmath}

\usepackage{amssymb}
\usepackage{cancel}
\usepackage{siunitx}
\usepackage{esint}
\usepackage{accents}
\usepackage{pgfplots}
\usepackage{tikzscale}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,patterns,angles,quotes}
\usepackage{pgf}
\usepackage{calc}
\usepackage{lastpage}
\usepackage{graphicx}
\usepackage{bigints}
\usepackage{array}
\usepackage[none]{hyphenat}
\usepackage[a4paper, portrait, right=20mm, left=20mm, top=25mm, bottom=20mm]{geometry}
\usepackage{url}
\usepackage{adjustbox}

\usepackage{subfiles}
%See https://en.wikibooks.org/wiki/LaTeX/Modular_Documents

\usepackage[hidelinks, linktoc=all]{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=black,
    filecolor=magenta,      
    urlcolor=blue,
    pdfpagemode=FullScreen,
}

\usepackage{xpatch}
\newlength{\beforechapskip}
\newlength{\chaptertopskip}
\newlength{\chapterbottomskip}
\setlength{\beforechapskip}{0mm}
\setlength{\chaptertopskip}{0mm}
\setlength{\chapterbottomskip}{10mm}



\renewcommand{\chaptermark}[1]{\markboth{\Large #1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}

\begin{document}

    \frontmatter
    \phantomsection 
    \hypertarget{ToC}{}  % Make an anchor to the toc
    \tableofcontents
    \thispagestyle{empty}
    \newpage

    \mainmatter
    %Defines numbering for pre-modules as roman
    \renewcommand{\thechapter}{\Roman{chapter}}
    \makeatletter
    \def\@makechapterhead#1{%
    \vspace*{\chaptertopskip}%
    {\parindent \z@ \raggedright \normalfont
        \ifnum \c@secnumdepth >\m@ne
        \if@mainmatter
            \huge\bfseries Pre-Module\space \thechapter:\
    %        \par\nobreak
    %        \vskip 20\p@

        \fi
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip \chapterbottomskip
    }}
    \makeatother
    % See https://tex.stackexchange.com/questions/309920/how-to-move-the-chapter-title-upwards-on-page

    %-------------------------------------------------------------------------------------------------------------
    %Defines numbering for pre-modules as roman

    \chapter{Example I}

    \chapter{Example II}


    \renewcommand{\thechapter}{\arabic{chapter}}
    %Defines numbering for modules as arabic numbering (normal)

     \makeatletter
     \def\@makechapterhead#1{%
     \vspace*{\chaptertopskip}%
     {\parindent \z@ \raggedright \normalfont
         \ifnum \c@secnumdepth >\m@ne
         \if@mainmatter
             \huge\bfseries Module\space \thechapter:\
     %        \par\nobreak
     %        \vskip 20\p@
         \fi
         \fi
         \interlinepenalty\@M
         \Huge \bfseries #1\par\nobreak
         \vskip \chapterbottomskip
     }}
     \makeatother
     % See https://tex.stackexchange.com/questions/309920/how-to-move-the-chapter-title-upwards-on-page
     %The guy from the internet basically had this word for word, though some changes have been made to make it say module and what not.
 
     \setcounter{chapter}{0}%makes the module numbering start at x+1, where x is the number here
 
 
     %-----------------------------------------------------------------------------------------------------------------------------------------------



     %Defines numbering for modules as arabic
     \chapter{Example 1}
     \chapter{Example 2}

\end{document}
1

1 Answer 1

2

Redefine also the counter representation of hyperref

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\theHchapter}{\Roman{chapter}}

 
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\theHchapter}{\arabic{chapter}}

Then hyperref has a chance to create unique destinations.

1
  • Yes that fixed it, thanks!
    – Alex
    Commented Jul 6, 2021 at 6:36

You must log in to answer this question.

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